Is it possible to get selections from python? #390
-
Hi, thank you so much for the fantastic project! Retrieving selections from an Altair chart is always something I need. I've experimented with Holoviz Panel, and it does allow me to access the selected items on an Altair chart. However, with Vega Fusion, I'm struggling to figure out how to retrieve my selections using Python code. My goal is to use the Vega Fusion chart to preview data and modify selections. Subsequently, I'd like to execute a more extensive query based on these selections in a separate Jupyter cell. There is something like this, unfortunately it does not work with widget renderer though. If Vega Fusion does not have any interface yet, please let me know any hacky way to achieve it as a temporary workaround. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
instead of using vf.enable_widget(), and just displaying the altair chart, i input my altair chart like: Now I see my selection is shown in web browser's console. Is there any workaround to get this selection in another jupyter cell? |
Beta Was this translation helpful? Give feedback.
-
Hi @jhyoo1982, glad to hear VegaFusion has been helpful for you! As you noted, it's not possible, today, to use the
When used this way, VegaFusion pre-transformes the data in the kernel before sending it to the client using the same logic as is performed for the VegaFusion mime renderer. The limitation of this approach is that any data that's used in a selection filter will be sent to the browser since there's no communication from the browser back to the python kernel. The VegaFusionWidget approach sends selection information from the browser back to the kernel so that the full dataset doesn't need to be sent to the browser. My goal is to re-build |
Beta Was this translation helpful? Give feedback.
Yeah, these are related. The bytes stored in
_request_msg
are serialized to the browser as an ipywidget traitlet. The browser deserializes them into aQueryResult
protocol buffer object, and the values are stored inside there.This QueryResult object is defined by the protocol buffer file at:
https://github.com/hex-inc/vegafusion/blob/f7a355f959a0e00db6daab828a711f2cca156d79/vegafusion-core/src/proto/services.proto#L21-L26
The deserialization happens in Rust, compiled to WASM, at
https://github.com/hex-inc/vegafusion/blob/f7a355f959a0e00db6daab828a711f2cca156d79/vegafusion-wasm/src/lib.rs#L178C29-L178C29.
So yeah, one option is that you could use the
protoc
command line tool to generate a…