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
AWLatin America & Caribbean ArubaOranjestad-70.01670012.516700
AFSouth AsiaAfghanistanKabul69.17610034.522800
AOSub-Saharan Africa AngolaLuanda13.242000-8.811550
ALEurope & Central AsiaAlbaniaTirane19.81720041.331700
ADEurope & Central AsiaAndorraAndorra la Vella1.52180042.507500
AEMiddle East & North AfricaUnited Arab EmiratesAbu Dhabi54.37050024.476400
ARLatin America & Caribbean ArgentinaBuenos Aires-58.417300-34.611800
AMEurope & Central AsiaArmeniaYerevan44.50900040.159600
ASEast Asia & PacificAmerican SamoaPago Pago-170.691000-14.284600
AGLatin America & Caribbean Antigua and BarbudaSaint John's-61.84560017.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.