3

I have a table and a plot below, I need to make the plot to be updated whenever a table cell is clicked.

ipywidgets library doesn't have a dedicated table widget.

qgrid doesn't have a callback for cell selection, only for row selection (I suspect I could hack it to react to cell clicks, but I guess the efforts required are comparable to making a raw html table clickable).

pivottablejs is cool, but it is an overkill for my task.

bokeh DataTable appears to have no callbacks at all.

4
  • In Bokeh you could have a JS or Python callbacks for` DataTable` via callback attached to its ColumnDataSource. You can check this post if it's what you want. Commented May 9, 2019 at 10:53
  • @Tony Do I understand correctly that in order to have python callbacks in this solution I need to start bokeh server? Commented May 9, 2019 at 11:00
  • Yes, Python callbacks are only possible when running Bokeh server. But It is also possible to detect cell clicks in a table using pure JS callback. See this post. The Python callback there was added to reset the indices but is not necessary anymore with the latest Bokeh v1.1.0 and can be omitted Commented May 9, 2019 at 11:02
  • @Tony Starting bokeh server doesn't fit in well into my workflow and I'd prefer python callbacks, so for now I'd stick to "emulating" table with the grid of ipywidgets buttons as described here: stackoverflow.com/questions/37528992/… Commented May 9, 2019 at 11:07

3 Answers 3

1

You can usually attach Python callbacks to Javascript objects using jp_proxy_widgets almost the normal way you would do it using only Javascript.

For example here I create a "vanilla" table and attach a click callback to a table element:

enter image description here

You can also do something similar with your favorite Javascript library (with some caveats -- see the documentation). Please have a look at jp_proxy_widgets here:

https://github.com/AaronWatters/jp_proxy_widget

Sign up to request clarification or add additional context in comments.

Comments

1

Streamlit provides editable dataframes:

df = pd.DataFrame( [ {"command": "st.selectbox", "rating": 4, "is_widget": True}, {"command": "st.balloons", "rating": 5, "is_widget": False}, {"command": "st.time_input", "rating": 3, "is_widget": True}, ] ) df = load_data() edited_df = st.data_editor(df) # 👈 An editable dataframe favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] st.markdown(f"Your favorite command is **{favorite_command}** 🎈") 

(example taken from their website)

Comments

0

You can do this now greatly with panel's new tabulator

Example:

import pandas as pd import panel as pn import numpy as np pn.extension('tabulator') sel_df = pd.DataFrame(np.random.randn(3, 5), columns=list('ABCDE')) select_table = pn.widgets.Tabulator(sel_df, selection=[0, 2]) def click(event): print(f'Clicked cell in {event.column!r} column, row {event.row!r} with value {event.value!r}') select_table.on_click(click) select_table 

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.