pandasaltairpywebview

pywebview "Save as PNG" unresponsive


I have a project using pywebview to display some data that I charted using Pandas and Altair. When using the interactive window that displays the charts, each chart has an option menu to save the chart as an SVG, PNG, etc...

But, none of the buttons work. Clicking the Save as PNG button gets no response. The only one that causes a response is the Save to SVG button, which focuses on that chart and locks the window. This is occurring on MacOS, while a collaborator says this works fine with his windows machine.

Here is a screenshot of what I mean: picture of menu

Here is a bit of the code:

pandas==2.0.3
pywebview==4.2.2
altair==5.0.1
PyAutoGUI==0.9.54
import pandas as pd
import altair as alt
import webview
import pyautogui

# ...
# a bunch of Pandas stuff to rename columns, sort, etc..

x_domain = [min(pd.DatetimeIndex(grouped_by_day.datetime) - pd.DateOffset(1)), max(pd.DatetimeIndex(grouped_by_day.datetime) + pd.DateOffset(1))]
y_domain = [min(grouped_by_day.glucose_value) - 10, max(grouped_by_day.glucose_value) + 10]

glucose = alt.Chart(grouped_by_day, title=alt.Title("Average Blood Glucose", fontSize=24)).mark_line(point=True).encode(
    x = alt.X('datetime:T',
                scale=alt.Scale(domain=x_domain),
                title="Date"
                ),
    y = alt.Y('glucose_value:Q', 
                scale=alt.Scale(domain=y_domain),
                title="Blood Glucose (mg/dL)"
                ),
    tooltip=[alt.Tooltip('datetime', title='Date'), alt.Tooltip('glucose_value', title='Glucose Value')]
).properties(
    width=screen_width-600,
    height=screen_heigth-400,
)

charts_html = f"""
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.8.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
</head>
<body>

<div id="vis1"></div>
<div id="vis2"></div>
<div id="vis3"></div>
<div id="vis4"></div>

<script type="text/javascript">
vegaEmbed('#vis1', {glucose.to_json()});
</script>
</body>
</html>
"""

# Display plots
webview.create_window('Dexcom Data Analysis', html=charts_html, width=screen_width, height=screen_heigth-50)
webview.start()

I have started a fresh venv and have the same result.


Solution

  • Author of pywebview here.

    Downloading files is not implemented for pywebview. The reason it works for Windows is downloading comes out of the box for WebView2 Chromium. For other platforms it must be tackled separately.