Static Preview#
Viewing a notebook with ITables tables on GitHub#
GitHub renders .ipynb files as non interactive HTML pages. If the notebook
outputs contain JavaScript code, that code is not executed. Since ITables tables are
normally interactive DataTables built with JavaScript, GitHub can’t show
them that way.
To address this, ITables v2.9+ ships a static preview with every table: a plain HTML table with just the first rows - 10 by default, or as many as your
pageLength/lengthMenu options say. GitHub shows that static preview
instead of the interactive table.
Untrusted notebooks, which can’t use JavaScript until you trust them, also use the same fallback - see Seeing a static preview instead?.
What the fallback looks like#
to_html_datatable shows that static preview - built with
to_html_static_preview - by default, right next to the interactive
table, which starts out hidden. A small inline script swaps the two
around wherever it actually gets to run (a real, JavaScript-capable
session): a <noscript> tag would not do here, since it only hides its
content when scripting is disabled for the whole page, which isn’t the
case on GitHub - GitHub’s notebook preview is itself a JavaScript-powered
page, it just doesn’t execute the <script> tags in our output. Here is
the static preview, the same plain HTML table you’d see on GitHub:
from IPython.display import HTML, display
import itables
df = itables.sample_dfs.get_countries()
display(HTML(itables.to_html_static_preview(df)))
| ⓘ | region | country | capital | longitude | latitude |
|---|---|---|---|---|---|
| code | |||||
| AW | Latin America & Caribbean | Aruba | Oranjestad | -70.016700 | 12.516700 |
| AF | South Asia | Afghanistan | Kabul | 69.176100 | 34.522800 |
| AO | Sub-Saharan Africa | Angola | Luanda | 13.242000 | -8.811550 |
| AL | Europe & Central Asia | Albania | Tirane | 19.817200 | 41.331700 |
| AD | Europe & Central Asia | Andorra | Andorra la Vella | 1.521800 | 42.507500 |
| AE | Middle East & North Africa | United Arab Emirates | Abu Dhabi | 54.370500 | 24.476400 |
| AR | Latin America & Caribbean | Argentina | Buenos Aires | -58.417300 | -34.611800 |
| AM | Europe & Central Asia | Armenia | Yerevan | 44.509000 | 40.159600 |
| AS | East Asia & Pacific | American Samoa | Pago Pago | -170.691000 | -14.284600 |
| AG | Latin America & Caribbean | Antigua and Barbuda | Saint John's | -61.845600 | 17.117500 |
| (198 more rows not shown) | |||||
An example notebook#
static_preview_demo.ipynb is a small notebook, generated and executed as part of ITables’ test suite, that demonstrates this fallback. Open it on GitHub to see the static preview tables, or download it and either run it, or trust it, to see the interactive tables instead.