- Design and publish
- CSS frameworks
- Advanced embedding
- It's been around for a while (they're on version 5.1)
- For simple apps, the default build may be all you need.
- As with most CSS frameworks, it can be customized.
- The examples are good...
- Bootstrap examples -- getbootstrap.com
- You can serve examples locally with a dev server, for example:
python -m http.server
- Then browse to http://localhost:8000
- Then navigate to any of the example directories
- For example, navbar components are here: http://localhost:8000/bootstrap-5.1.3-examples/navbars/
- You can serve examples locally with a dev server, for example:
- The framework organizes things into components
- Some require JavaScript
- You can load the CSS and JS locally or from the cloud
Get the bootstrap dashboard example running locally on your machine.
- Open a terminal from which you can run Python
- Download and unzip the zip file into a local directory ./bootstrap-5.1.3-examples
- Create a local copy of the "index.html" file from "./bootstrap-5.1.3-examples/dashboard", call it "orig.html"
- Copy "bootstrap.min.css", "bootstrap.bundle.min.js", "dashboard.css" and "dashboard.js" to the local directory.
- Adjust the URLs in "index.html" to look for the local files.
- Start the dev server (from the directory with "orig.html"):
python -m http.server
- Then browse to http://localhost:8000/orig.html
Solution: http://localhost:8000/orig.html
You're familiar with embedding an entire notebook, or a subset of a notebook...
You can also integrate individual cells from a notebook into elements of a web page that's styled with bootstrap, which provides much more design flexibility...
The section on "Rendering cells" shows how to insert a cell into a container element.
Put the map and the table from NOAA weather data by major U.S. city into the bootstrap dashboard example.
- Replace the chart with the map, and the hard-coded table with the table from the notebook.
- Create your own fork of https://observablehq.com/@observablehq/noaa-weather-data-by-major-u-s-city
- Evidently, this is necessary for a CORS-enabled notebook API.
- You can verify the problem in the development console.
- Solution: Exercise 2
Solution: http://localhost:8000/second.html
- Responsive design -- MDN
- The references discusses issues related to cross-browser and multiple device support.
- Responsive design can be a challenge when dealing with CSS.
- Responsive tables with bootstrap
- CSS width
- To fit the container, use "width: 100%;
- To opt in to the bootstrap styling of tables, use
class="table"
Make the table responsive.
Solution: http://localhost:8000/third.html
- Responsive images
- SVG and canvas elements can maintain a constant apect ratio, but need appropriate CSS styling
- Bootstrap handles this with the
img-fluid
class - This class needs to be set on the
canvas
orsvg
- You an also set the appropriate class in the original notebook.
- However, if you take this approach, interaction with the map won't work.
- The best way: Set
width
by overriding cell values- See Advanced Downloading and Embedding
- We want to specify the width width in the notebook
- We want to set width to equal the width of the containing element.
- We'll use the
<div>
's offsetWidth - Then use:
main.redefine("data", newData);
in our casemain.redefine("width", div.offsetWidth)
Make the chart (map) responsive.
Solution: http://localhost:8000/fourth.html
Add the search input to the dashboard
Solution: http://localhost:8000/fifth.html
Create a multi-page app from one of the bootstrap examples.
Solution:
$ cd basic
$ python -m http.server
Browse to: http://localhost:8000/