-
Notifications
You must be signed in to change notification settings - Fork 794
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
Should JupyterCharts fire a callback when the selection changes? #3238
Comments
Each individual selection is a traitlet property of the Does this workflow not line up with what Shiny needs? It might be possible to make |
Hi @jonmmease 👋 😄
It does, I was just a bit surprised that I don't have enough context to have a strong opinion on whether |
Awesome that you have a working example @cpsievert! I'm not so much in favour of supporting a general @jonmmease, I remember we discussed this at the VegaConf as well, currently we have to differentiate between jchart.params.observe(on_width_change, ["width"])
jchart.selections.observe(on_interval_change, ["interval"]) For me, and according the VL-docs, selections are a subset of @cpsievert, I have one question if you don't mind. I was playing a bit with the shiny approach, but I'm not really sure how I can update widgets. I can [..]
jchart = alt.JupyterChart(chart)
register_widget("my_chart", jchart)
@reactive.event(input.toggle)
def _():
jchart.chart = chart.mark_bar(color="crimson", cornerRadius=10) |
@mattijn you were so close...you just need to use the |
Ah great! Thanks @cpsievert! Another way how we can make this more convenient is to accept an brush = alt.selection_interval() # no manual defined `name=`
chart = alt.Chart().add_params(
brush
)
jchart = alt.JupyterChart(chart)
jchart.params.observe(callback, brush) # name of `brush` can be found using `brush.name` But would this hold elsewhere? Eg. is the following still valid?
Would be great! |
Nice, shinywidgets wouldn't support that (i.e., passing a non-string to Also, as long as we're stilling dreaming up an API, |
Agree! |
@cpsievert,Indeed, it was unexpected for me to discover that the jchart.observe(callback, "selections") method does not trigger, which I believe will similarly catch Shiny users off guard when they notice that reactive_read(jchart, "selections") does not refresh the reactive environment. Without more information, I don't feel qualified to firmly advocate for or against the support of jchart.observe(callback, "selections"). Although I understand the reasoning behind not promoting its use, especially when one is interested in monitoring only specific types of selections, I do think its inclusion could lower the initial learning curve for newcomers. |
Hi @shawnhu444! Thanks for commenting. I'm not a Shiny user myself, but I'm trying to understand this further. Could you explain why you would expect that |
I'm experimenting with using Altair together with the Shiny dashboarding framework for Python, and thanks to the JupyterChart widget that @jonmmease added it seems like this is working out of the box! This is super convenient and means that Altair is one of the few (maybe the only?) viz package can trigger events from chart selections with Shiny.
One comment I received when trying to understand better how to make Altair and Shiny work nicely together was that it would be easier if
jchart.observe(callback, "selections")
would fire a callback when the selection changes. I am not familiar enough with the internals of JupyterChart to know if this is something that would be beneficial to add, so I wanted to bring it up here and hear if anyone has thoughts on this, mostly @jonmmease.The text was updated successfully, but these errors were encountered: