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

Is there interaction possible between itables and the altair package (graphs) ? #334

Open
tomnobelsAM opened this issue Nov 12, 2024 · 1 comment

Comments

@tomnobelsAM
Copy link

It would be nice if there could be an interaction between these 2 packages
If you click on a graph , you get the details in itables or if you make a selection in itables , you get a graph visualisation in altair.

Do you think this is possible ?

Thanks in advance

@mwouts
Copy link
Owner

mwouts commented Nov 14, 2024

Hello @tomnobelsAM , great question, thanks! That is possible indeed.

You will need to choose an "application" framework that is supported by both ITables and your graph library (e.g. Jupyter Widgets, Streamlit, Shiny for Python as far as ITables is concerned).

Then you will use either the graph state to change the content of your table, or the selected row(s) in the table to change the content of the graph.

In the documentation we have an example that updates the content of a table depending on a dropdown object:

import ipywidgets as widgets
from itables import show
from itables.sample_dfs import get_dict_of_test_dfs

def use_show_in_interactive_output(table_name: str):
    show(
        sample_dfs[table_name],
        caption=table_name,
    )

sample_dfs = get_dict_of_test_dfs()
table_selector = widgets.Dropdown(options=sample_dfs.keys(), value="int_float_str")

out = widgets.interactive_output(
    use_show_in_interactive_output, {"table_name": table_selector}
)

widgets.VBox([table_selector, out])

The other way around, getting the selected rows in an ITable widget is easily done with the .selected_rows trait (use select="single" rather than select=True if you want to allow selecting only one row).

The other supported frameworks include Streamlit (which seems to support Altair plots) and Shiny for Python.

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

No branches or pull requests

2 participants