回答編集履歴
2
コード更新
answer
CHANGED
@@ -4,21 +4,28 @@
|
|
4
4
|
こちらのライブラリ [https://github.com/null-jones/streamlit-plotly-events](https://github.com/null-jones/streamlit-plotly-events) は使えないでしょうか。
|
5
5
|
|
6
6
|
### 追加
|
7
|
-
ためしに作ってみました。
|
7
|
+
ためしに作ってみました。(コメントをうけてコードを更新しました)
|
8
8
|
```python
|
9
9
|
import pandas as pd
|
10
10
|
import plotly.express as px
|
11
|
+
import plotly.graph_objects as go
|
11
12
|
import streamlit as st
|
12
13
|
from streamlit_plotly_events import plotly_events
|
14
|
+
import plotly.offline as offline
|
13
15
|
|
14
16
|
df = pd.DataFrame({'X': [1, 1, 2, 2, 3, 3], 'Y': [1, 3, 2, 3, 1, 2]})
|
17
|
+
df2 = pd.DataFrame({'X': [0, 0.5, 1, 1.5, 2, 2.5], 'Y': [1, 3, 2, 3, 1, 2]})
|
15
18
|
|
16
|
-
# Select other Plotly events by specifying kwargs
|
17
|
-
|
19
|
+
fig1 = px.scatter(df, x='X', y='Y')
|
18
|
-
|
20
|
+
fig1.update_layout(clickmode='select')
|
21
|
+
fig2 = px.line(df2,x='X', y='Y')
|
22
|
+
|
23
|
+
fig = go.Figure(data=fig1.data + fig2.data)
|
24
|
+
|
19
25
|
selected_points = plotly_events(fig, click_event=False, select_event=True)
|
20
26
|
|
21
27
|
df.iloc[[v['pointIndex'] for v in selected_points]]
|
22
28
|
```
|
29
|
+
|
23
30
|
もうちょっとやりたいことが複雑なら、
|
24
31
|
素直にdashを使った方がいいような気がします。
|
1
追加
answer
CHANGED
@@ -1,4 +1,24 @@
|
|
1
1
|
こちらのissue([https://github.com/streamlit/streamlit/issues/455](https://github.com/streamlit/streamlit/issues/455))のとおり、
|
2
2
|
そういうことをしたいというリクエストは前からあるけど、現時点では機能が実装されていない状況だと思われます。
|
3
3
|
|
4
|
-
こちらのライブラリ [https://github.com/null-jones/streamlit-plotly-events](https://github.com/null-jones/streamlit-plotly-events) は使えないでしょうか。
|
4
|
+
こちらのライブラリ [https://github.com/null-jones/streamlit-plotly-events](https://github.com/null-jones/streamlit-plotly-events) は使えないでしょうか。
|
5
|
+
|
6
|
+
### 追加
|
7
|
+
ためしに作ってみました。
|
8
|
+
```python
|
9
|
+
import pandas as pd
|
10
|
+
import plotly.express as px
|
11
|
+
import streamlit as st
|
12
|
+
from streamlit_plotly_events import plotly_events
|
13
|
+
|
14
|
+
df = pd.DataFrame({'X': [1, 1, 2, 2, 3, 3], 'Y': [1, 3, 2, 3, 1, 2]})
|
15
|
+
|
16
|
+
# Select other Plotly events by specifying kwargs
|
17
|
+
fig = px.scatter(df, x='X', y='Y')
|
18
|
+
fig.update_layout(clickmode='select')
|
19
|
+
selected_points = plotly_events(fig, click_event=False, select_event=True)
|
20
|
+
|
21
|
+
df.iloc[[v['pointIndex'] for v in selected_points]]
|
22
|
+
```
|
23
|
+
もうちょっとやりたいことが複雑なら、
|
24
|
+
素直にdashを使った方がいいような気がします。
|