-
Notifications
You must be signed in to change notification settings - Fork 18
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
No data is shown when using the widget renderer from an IDE to a browser #334
Comments
Hi @T-Flet, thanks for the question. tl;dr The widget renderer is not compatible with The widget renderer is based on a custom Jupyter Widget, so it will only work in contexts that are compatible with Jupyter Widgets. This includes the Jupyter Notebook, JupyterLab, Visual Studio Code notebook, Colab, and some other notebook environments. But AFAIK, there's not an easy solution for displaying Jupyter widgets in standalone browser windows from a Python script. What makes this tricky at a technical level is that Jupyter widgets require two-way communication between the Python kernel and the browser. Could you add a little more detail on your desired workflow?
As a workaround for aggregated charts or moderate sized scatter charts (a few tens of thousands of rows) the |
Thank you for the quick reply; perfectly reasonable and concise explanation. Replying to your specific queries:
Altair + VegaFusion's widget renderer seems to be a perfect match for my preferences and needs (grammar-of-graphics plotting + interactivity and avoiding sending all data at once); is there a way to make the above work? If not an exact way, is there something close I could do? |
Thanks for the additional details @T-Flet, The use case of running VegaFusion outside of Jupyter with two-way communication wired up crosses into the territory of a full Python dashboarding toolkit. Presently, I'm aware of 3 Python dashboarding toolkits that have some support for Jupyter Widgets: Voila, Panel, and Solara. Currently, Voila works well with From what I understand about your use case (and about Solara), I think Solara is currently the best solution for running VegaFusionWidget from a standalone Python script. Here's an example:
Create a file named from vega_datasets import data
import altair as alt
import vegafusion as vf
source = alt.UrlData(
data.flights_2k.url,
format={'parse': {'date': 'date'}}
)
brush = alt.selection_interval(encodings=['x'])
# Define the base chart, with the common parts of the
# background and highlights
base = alt.Chart(width=160, height=130).mark_bar().encode(
x=alt.X(alt.repeat('column')).bin(maxbins=20),
y='count()'
)
# gray background with selection
background = base.encode(
color=alt.value('#ddd')
).add_params(brush)
# blue highlights on the transformed data
highlight = base.transform_filter(brush)
# layer the two charts & repeat
chart = alt.layer(
background,
highlight,
data=source
).transform_calculate(
"time",
"hours(datum.date)"
).repeat(column=["distance", "delay", "time"])
chart_widget = vf.jupyter.VegaFusionWidget(chart) Then launch it from the command line with:
And the nice thing about this approach is that you can use all of the built-in ipywidgets as well (like dropdowns, layouts, tabs, etc. See https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html). See what you think! |
Thank you for going above and beyond the original tentative-bug-report / query. SolaraI tried the Solara example both in the conda environment I need it in and in a fresh one (also Python 3.10), and in both cases I get the same error on the browser side:
Do you think this is a problem on my end, on VegaFusion's or should this be raised to a Solara issue referencing the one you raised and closed for that example? JupyterSeparately, it seems from the available options (please correct me if I am wrong) that I need to save the data to disk and run a separate visualisation in any case, as opposed to my original usecase intent of letting a program hang with it in RAM until plots are closed (I do realise that VegaFusion saves temporary feather files). I tried the widget renderer example in the documentation in VS Code, where no errors are raised (ignoring deprecations due to altair 5.x) but it is not clear whether the plot is generated since the widget area is too small: Everything displays normally in a standard jupyter notebook (deprecations but present and working plot). |
Have you updated to vegafusion/vegafusion-jupyter But now that I wrote this, I just checked and it looks like the conda-forge packages for vegafusion-jupyter 1.3.0 didn't go through. I'll have to look into that. edit: Also, thanks for the reminder that this example needs to be updated to Altair 5! |
Ok, vegafusion-jupyter 1.3.0 is now on conda-forge. I don't know that this will fix the solara issue you're seeing, but worth a try. |
I am afraid both |
Could you try adding the e.g. vf.jupyter.VegaFusionWidget(chart, verbose=True) Also, do you get this same error for the exact example I posted above? I'm wondering if the error happens for every chart, or if it's only for particular chart types. It's also worth force reinstalling
|
I force-reinstalled (Not relevant now since it works, but adding (Yes, the example was exactly the one you posted.) The weird no-plot behaviour in VS Code persists, but I am happy to close this issue and open another for it if you prefer (or deem it worthy of one). |
That's great to hear! Yeah, I'll close this and you can open another issue on the VSCode issue. Thanks |
What is the intended/supported behaviour when running the widget renderer from a script in an IDE?
Minimal example: the widget renderer example in the documentation with an added
.show()
on the last line (since justchart
does nothing in non-notebook context).When trying this from an IDE (e.g. PyCharm), the plot is served on localhost and a browser tab is automatically opened, but no data is received by it (i.e. the 3 plot areas are there but empty).
A warning for the data not being found is issued (although the mentioned file IS there on inspection):
If a data folder is specified (i.e.
vf.enable_widget(data_dir = ...)
at the beginning of the example), then the no-data behaviour persists but no warning is issued.Is this behaviour expected and/or correctable?
As a separate note, the example works "fine" (very slowly) with altair_data_server (i.e. replacing
vf.enable_widget()
withalt.data_transformers.enable('data_server')
), thus not pointing to the typical causes of no-data being shown mentioned in the altair documentation.Versions:
The text was updated successfully, but these errors were encountered: