Ich versuche, mein Plotly -Diagrammobjekt in eine PNG in meiner Streamlit -App zu exportieren. so aussieht wie folgt: < /p>
import plotly.graph_objects as go
import plotly.io as pio
import streamlit as st
def main():
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[3, 2, 1], mode='markers'))
filename = 'image.png'
with st.spinner('exporting image'):
try:
pio.write_image(fig, filename, format="png", engine="kaleido")
print("Image export successful.")
except Exception as e:
print(f"Image export failed: {e}")
with open(filename, "rb") as file:
st.download_button(
label="Download Plot as PNG",
data=file,
file_name=filename,
mime="image/png"
)
if __name__ == '__main__':
main()
< /code>
Meine App steckt in der Funktion write_image fest. Wenn ich den folgenden Code ausführe, der nicht Teil einer Streamlit -App ist, läuft er vollkommen in Ordnung. < /P>
import plotly.graph_objects as go
from plotly.io import to_image
# Test Plotly GO image export locally
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[3, 2, 1], mode='markers'))
try:
img = to_image(fig, format="png")
print("Image export successful.")
except Exception as e:
print(f"Image export failed: {e}")
< /code>
Ich habe Python 3.11 und 3.9 mit Plotly 6.0.0, Kaleido 0.4.1 und Plotly 5.5.0 und Kaleido 0.2.1 Respivley < /p>
ausprobiert. Ich habe das Fix hier ausprobiert: Speichern eines Handlungsbildes funktioniert nicht mit Kaleido, obwohl es hier installiert ist. 61
ohne Glück ...
Weiß jemand, wie man dieses Problem angeht?
Diagramm -Diagrammobjekt, das nicht als PNG in der streamlit -App exportiert wird ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Es gibt ein Problem, das die GUI exportiert, die ich in ein PDF entworfen habe
by Anonymous » » in Python - 0 Replies
- 6 Views
-
Last post by Anonymous
-