Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a streamlit component for ITables #270

Merged
merged 1 commit into from
May 26, 2024
Merged

Conversation

mwouts
Copy link
Owner

@mwouts mwouts commented May 12, 2024

The purpose of this PR is to provide a component that would display a DataFrame in a streamlit app.

The first version of the component could have the following limitations:

  • complex columns would not be supported
  • custom JS code would not be supported
  • the component does not return any data from the JS side (rows selected etc won't be accessible yet)

TODO:

  • extract a function from to_html_datatable that, given a dataframe and the usual arguments, returns the arguments to be passed to DataFrame on the JS end
  • In addition, for the present use case, that function would have to set a columns argument too (since we don't pass a HTML header for the table)
  • The frontend for our streamlit component should depend on dt_for_itables, in order to provide the same datatables extensions in Streamlit as in Jupyter Notebooks.
  • Test the light and dark mode

Copy link

Thank you for making this pull request.

Did you know? You can try it on Binder: Binder:lab.

Also, the version of ITables developed in this PR can be installed with pip:

pip install git+https://github.com/mwouts/itables.git@streamlit_component

(this requires nodejs, see more at Developing ITables)

Base automatically changed from src_layout to main May 26, 2024 15:48
@mwouts mwouts force-pushed the streamlit_component branch 13 times, most recently from 2a97b60 to ab135ef Compare May 26, 2024 23:14
@mwouts mwouts marked this pull request as ready for review May 26, 2024 23:15
@mwouts mwouts merged commit 877a4d8 into main May 26, 2024
14 checks passed
@mwouts mwouts deleted the streamlit_component branch May 26, 2024 23:28
@mwouts
Copy link
Owner Author

mwouts commented May 27, 2024

The latest version of itables includes a streamlit component.

Install it with

pip install 'itables>=2.1.0'

To display a dataframe in a streamlit app, just type:

from itables.streamlit import interactive_table

interactive_table(df)

The interactive_table function takes the same parameter as the show function, up to certain limitations (in short: multi indexed columns will look a bit different, passing javascript code is not supported, pandas Style objects are not supported).

See the documentation at https://mwouts.github.io/itables/streamlit.html

A sample application is available at https://itables.streamlit.app/, see https://github.com/mwouts/demo_itables_in_streamlit for the source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant