from ipyleaflet import Map, Marker, basemaps, basemap_to_tiles
= Map(
m =basemap_to_tiles(
basemap"2017-04-08"
basemaps.NASAGIBS.ModisTerraTrueColorCR,
),=(52.204793, 360.121558),
center=4
zoom
)=(52.204793, 360.121558)))
m.add_layer(Marker(location m
Jupyter Widgets
Overview
Jupyter Widgets enable you to use JavaScript visualization libraries like Leaflet, Plotly, and threejs directly from Python.
If you are using the Jupyter engine with Quarto this is a great way to incorporate interactivity without learning JavaScript.
Note that while Quarto uses a Jupyter kernel during rendering, there is no Jupyter kernel once the site is published, so there is interactivity with JavaScript but not with Python.
Leaflet Example
Including Jupyter Widgets within a Quarto document is as easy as including a plot. For example, here is how we embed a Leaflet map:
To learn about available Jupyter Widgets visit https://jupyter.org/widgets.
Plotly
Plotly is an interactive graphics library that can also be used with the Jupyter engine. Here’s an example of using Plotly:
import plotly.express as px
import plotly.io as pio
= px.data.iris()
df = px.scatter(df, x="sepal_width", y="sepal_length",
fig ="species",
color="violin", marginal_x="box",
marginal_y="ols", template="simple_white")
trendline fig.show()
If you are using Plotly within the VS Code Notebook Editor you will need to add a line of code to ensure that your plots can be seen both within VS Code and when rendered to HTML by Quarto. You can do this by configuring the Plotly default renderer as follows:
```{python}
import plotly.io as pio
= "plotly_mimetype+notebook_connected"
pio.renderers.default ```
This workaround is required because when running within VS Code, Plotly chooses a default rendering that can’t be easily exported to HTML (for more background, see this GitHub Issue and related discussion). Note that this workaround is only required for the VS Code Notebook Editor (it is not required if you are using Jupyter Lab or if you are editing a plain-text .qmd
file).