mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
771 stars 56 forks source link

Feature request - support for shiny #86

Closed iainmwallace closed 2 years ago

iainmwallace commented 2 years ago

Hi,

I was wondering if you had considered supporting use of your package within shiny apps - https://shiny.rstudio.com/py/. It would be a great contribution to the ecosystem :)

The R DT package is widely used in R/Shiny apps in part due to the excellent documentation - https://rstudio.github.io/DT/shiny.html

Thanks

Iain

mwouts commented 2 years ago

Hi @iainmwallace , thanks for suggesting this. I think it should be doable to make itables work in the context of a Shiny app.

Some developments would be required on our end because py-shiny does not seem to be directly compatible with the display function of IPython. At the current stage of development of py-shiny, the render.table decorator calls explicitely df.to_html https://github.com/rstudio/py-shiny/blob/2655fb487412881d7a946f7b8db41f9746a85678/shiny/render/_render.py#L526. This is different to how itables currently works in notebooks, where we just override pd.DataFrame._repr_html_, cf. https://github.com/mwouts/itables/blob/ec388a71f574fa8e1f3cc59108f8a0df1375a077/itables/javascript.py#L72

Before undertaking any such development, let me ask to the py-shiny developers whether they would consider supporting outputs coming from IPython.display calls.

mwouts commented 2 years ago

I have been able to display a dataframe as an interactive datatable in a Shiny app with just ui.HTML(DT(df)), where DT is defined as

from itables.javascript import _datatables_repr_ as DT

See this comment for the full example (I am not sure at the moment if this is a sound approach!)

iainmwallace commented 2 years ago

Fantastic, thanks @mwouts. The examples you posted on the other issue are really useful.

mwouts commented 2 years ago

Up-to-date tested examples are available at https://github.com/mwouts/itables/tree/main/tests/sample_python_apps