Skip to content

Commit 15796f3

Browse files
author
Hugo Le Bars
committed
[fit] update to plotly.js 2.20.0
1 parent f7b517a commit 15796f3

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

src/streamlit_plotly_events/__init__.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2-
import streamlit.components.v1 as components
32
from json import loads
43

4+
import streamlit.components.v1 as components
5+
56
# Create a _RELEASE constant. We'll set this to False while we're developing
67
# the component, and True when we're ready to package and distribute it.
78
# (This is, of course, optional - there are innumerable ways to manage your
@@ -113,8 +114,9 @@ def plotly_events(
113114
# During development, we can run this just as we would any other Streamlit
114115
# app: `$ streamlit run src/streamlit_plotly_events/__init__.py`
115116
if not _RELEASE:
116-
import streamlit as st
117117
import plotly.express as px
118+
import plotly.graph_objects as go
119+
import streamlit as st
118120

119121
st.set_page_config(layout="wide")
120122

@@ -148,3 +150,32 @@ def plotly_events(
148150
fig4, key="hover", click_event=False, hover_event=True
149151
)
150152
plot_name_holder4.write(f"Hovered Point: {clickedPoint4}")
153+
st.subheader("# Plotly Heatmap with click Event and text")
154+
z = [
155+
[0.1, 0.3, 0.5, 0.7, 0.9],
156+
[1, 0.8, 0.6, 0.4, 0.2],
157+
[0.2, 0, 0.5, 0.7, 0.9],
158+
[0.9, 0.8, 0.4, 0.2, 0],
159+
[0.3, 0.4, 0.5, 0.7, 1],
160+
]
161+
162+
y = [
163+
["t", "a", "b", "j", "h"],
164+
["d", "d", "d", "k", "h"],
165+
["n", "b", "r", "b", "b"],
166+
["d", "t", "y", "m", "g"],
167+
["s", "q", "b", "b", "h"],
168+
]
169+
fig5 = go.Figure()
170+
fig5.add_trace(
171+
go.Heatmap(
172+
z=z,
173+
texttemplate="%{text}",
174+
text=y,
175+
colorscale="viridis",
176+
hovertemplate="%{text}<br>x: %{x}<br>y: %{y}<br>z: %{z}<extra></extra>",
177+
)
178+
)
179+
plot_name_holder5 = st.empty()
180+
clickedPoint5 = plotly_events(fig5, click_event=True, key="heatmap with text")
181+
plot_name_holder5.write(f"Clicked Point: {clickedPoint5}")

src/streamlit_plotly_events/frontend/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
"@types/node": "^12.0.0",
1111
"@types/react": "^16.9.0",
1212
"@types/react-dom": "^16.9.0",
13-
"plotly.js": "^1.58.2",
13+
"plotly.js": "^2.20.0",
1414
"react": "^16.13.1",
1515
"react-dom": "^16.13.1",
1616
"react-plotly.js": "^2.4.0",
17-
"react-scripts": "3.4.1",
18-
"streamlit-component-lib": "^1.2.0",
19-
"typescript": "~3.7.2"
17+
"react-scripts": "~4.0.1",
18+
"streamlit-component-lib": "^1.3.0",
19+
"typescript": "^4.2.0"
2020
},
2121
"devDependencies": {
2222
"@types/plotly.js": "^1.50.16",
@@ -44,4 +44,4 @@
4444
]
4545
},
4646
"homepage": "."
47-
}
47+
}

src/streamlit_plotly_events/frontend/src/StreamlitPlotlyEventsComponent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class StreamlitPlotlyEventsComponent extends StreamlitComponentBase {
2525
layout={plot_obj.layout}
2626
config={plot_obj.config}
2727
frames={plot_obj.frames}
28-
onClick={click_event ? this.plotlyEventHandler : function(){}}
29-
onSelected={select_event ? this.plotlyEventHandler : function(){}}
30-
onHover={hover_event ? this.plotlyEventHandler : function(){}}
31-
style={{width: override_width, height: override_height}}
28+
onClick={click_event ? this.plotlyEventHandler : function () { }}
29+
onSelected={select_event ? this.plotlyEventHandler : function () { }}
30+
onHover={hover_event ? this.plotlyEventHandler : function () { }}
31+
style={{ width: override_width, height: override_height }}
3232
className="stPlotlyChart"
3333
/>
3434
)

src/streamlit_plotly_events/frontend/tsconfig.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": ["dom", "dom.iterable", "esnext"],
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
59
"allowJs": true,
610
"skipLibCheck": true,
711
"esModuleInterop": true,
@@ -13,7 +17,10 @@
1317
"resolveJsonModule": true,
1418
"isolatedModules": true,
1519
"noEmit": true,
16-
"jsx": "react"
20+
"jsx": "react-jsx",
21+
"noFallthroughCasesInSwitch": true
1722
},
18-
"include": ["src"]
23+
"include": [
24+
"src"
25+
]
1926
}

0 commit comments

Comments
 (0)