r/PyScript • u/kland2005 • Jan 12 '24
Plotly issue - Display the figure
Dear PyScript community,
I would like to switch from MATPLOTLIB to Plotly in a project. All my attempts to display the Plotly figure have not worked. Here is the structure of my code:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Plotly Demo</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2024.1.1/core.css">
<script type="module" src="https://pyscript.net/releases/2024.1.1/core.js"></script>
</head>
<body>
<h1>Plotly Demo</h1>
<div id="output"></div>
<script type="py" src="./main.py" config="./pyscript.json"></script>
</body>
</html>pyscript.json
{
"packages": ["plotly"]
}main.py
from pyscript import display
import plotly.graph_objects as go
fig = go.Figure([go.Bar(x=['product a', 'product b', 'product c'], y=[5, 3, 2])])
display(fig, target='output')I don't see anything as a result. Does anyone of you have an idea how I can display the figure? Any help would be appreciated.
Thanks and kind regards
Klaus
1
Upvotes
View all comments
Show parent comment
1
u/kland2005 Jan 13 '24
Thank you - I will have a deep look into this later.
I tried a little further: Surprisingly, my example works when I call up the figure via a button click - strange.
https://pyscript.com/@dragor/plotly-demo/latest
At the moment I still have to click the button twice, but I'll keep trying.