HTML export

HTML export#

To get the HTML representation of a Pandas DataFrame df as an interactive DataTable, you can use to_html_datatable as below:

from IPython.display import HTML, display

from itables import to_html_datatable
from itables.sample_dfs import get_countries

df = get_countries(html=False)
html = to_html_datatable(df.head(3), display_logo_when_loading=False)

You can then save the html variable to a text file (note: if you’re writing an HTML application, you could consider using Shiny or Streamlit instead), or print it:

<table id="itables_e8f94d01_8639_45ae_a3ac_a63100357ac2" class="display nowrap" data-quarto-disable-processing="true" style="table-layout:auto;width:auto;margin:auto;caption-side:bottom">
    <tr style="text-align: right;">
<td style="vertical-align:middle; text-align:left">
Loading ITables v2.1.4 from the internet...
(need <a href=>help</a>?)</td>

<link href="" rel="stylesheet">
<script type="module">
    import {DataTable, jQuery as $} from '';

    document.querySelectorAll("#itables_e8f94d01_8639_45ae_a3ac_a63100357ac2:not(.dataTable)").forEach(table => {
        // Define the table data
        const data = [["AW", "Latin America & Caribbean ", "Aruba", "Oranjestad", -70.0167, 12.5167], ["AF", "South Asia", "Afghanistan", "Kabul", 69.1761, 34.5228], ["AO", "Sub-Saharan Africa ", "Angola", "Luanda", 13.242, -8.81155]];

        // Define the dt_args
        let dt_args = {"layout": {"topStart": null, "topEnd": null, "bottomStart": null, "bottomEnd": null}, "order": []};
        dt_args["data"] = data;

        new DataTable(table, dt_args);

or display it, like show does:

region country capital longitude latitude
Loading ITables v2.1.4 from the internet... (need help?)