teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

9

修正

2021/07/05 00:28

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
File without changes
body CHANGED
@@ -4,8 +4,8 @@
4
4
  これを1つのグラフが更新されるように修正したいのですが、
5
5
  どなたか教えていただければと思います。
6
6
  よろしくお願いします。
7
+ ```python
7
8
 
8
-
9
9
  import pandas as pd
10
10
  import plotly.express as px
11
11
  import streamlit as st
@@ -44,4 +44,6 @@
44
44
  df = df[~df['X'].isin(df_final['X'])]
45
45
  counter = counter + 1
46
46
  except:
47
- break
47
+ break
48
+
49
+ ```

8

内容の修正

2021/07/05 00:27

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- plotlyのグラフ更新(streamlit)
1
+ plotlyのグラフ表示の更新
body CHANGED
@@ -1,18 +1,11 @@
1
- 現在、Plotlyでのグラフ表示をしてい
1
+ 現在、Streamlitを使って、グラフ表示されている点を選択ると
2
+ グラフが更新され、先ほど選択した点が消えた状態になれば良いのですが、
3
+ 現状は、どんどん新しいグラフが追加されていくようになっております。
2
- 当初描画さているグラフを下の数値を使って更新したいです
4
+ を1つのグラフ更新されるように修正したいですが、
3
- 何か方法などありますでしょうか??
4
- 一応、下のもので、削除はされていくのですが、削除するたびに更新ではなく、
5
- グラフが新しく作成される状態になりました。
6
- また、エラーも出るようにしまっています
5
+ たか教えていただければと思います
7
- *******************************************************
6
+ よろしくお願いします。
8
- DuplicateWidgetID: There are multiple identical st.streamlit_plotly_events.plotly_events widgets with the same generated key.
9
7
 
10
- When a widget is created, it's assigned an internal key based on its structure. Multiple widgets with an identical structure will result in the same internal key, which causes this error.
11
8
 
12
- To fix this error, please pass a unique key argument to st.streamlit_plotly_events.plotly_events.
13
- *******************************************************
14
- よろしくお願いいたします。
15
-
16
9
  import pandas as pd
17
10
  import plotly.express as px
18
11
  import streamlit as st
@@ -24,15 +17,31 @@
24
17
  df2 = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
25
18
 
26
19
  aaa = st.checkbox('AAA')
20
+ counter = 0
27
21
 
28
22
  while aaa == True:
29
23
  st.write(df)
24
+ st.write(counter)
25
+ key = "hover" +'_'+ str(counter)
26
+ st.write(key)
30
27
  fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
31
28
  fig2 = px.line(df2,x='X', y='Y')
32
29
  fig1.update_layout(clickmode='select')
33
30
  fig = go.Figure(data=fig1.data + fig2.data)
31
+ selected_points = plotly_events(
32
+ fig,
33
+ click_event = False,
34
+ select_event = True,
35
+ override_height = 500,
36
+ override_width = "100%",
37
+ key = key
38
+ )
39
+ try:
34
- selected_points = plotly_events(fig, click_event=False, select_event=True)
40
+ selected_points = eval(selected_points)
35
- df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
41
+ df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
36
- st.write(df_final)
42
+ st.write(df_final)
37
- st.write('削除後の点は以下')
43
+ st.write('削除後の点は以下')
38
- df = df[~df['X'].isin(df_final['X'])]
44
+ df = df[~df['X'].isin(df_final['X'])]
45
+ counter = counter + 1
46
+ except:
47
+ break

7

ソース変更、文言の修正

2021/07/03 10:16

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- plotlyのグラフ更新(streamlit)
1
+ plotlyのグラフ更新(streamlit)
body CHANGED
@@ -1,8 +1,16 @@
1
1
  現在、Plotlyでのグラフ表示をしています。
2
2
  当初描画されているグラフを下の数値を使って更新したいです。
3
3
  何か方法などありますでしょうか??
4
- ソース内いうと最終的に出きたdf_final2を使ってscatterを描画した更新したい)す。
4
+ 一応、下のもので、削除はされていくのですが、削除するたびに更新ではなく、
5
- ちなみ、px.lineの値はそのまです
5
+ グラフが新しく作成される状態なりした
6
+ また、エラーも出るようになってしまっています。
7
+ *******************************************************
8
+ DuplicateWidgetID: There are multiple identical st.streamlit_plotly_events.plotly_events widgets with the same generated key.
9
+
10
+ When a widget is created, it's assigned an internal key based on its structure. Multiple widgets with an identical structure will result in the same internal key, which causes this error.
11
+
12
+ To fix this error, please pass a unique key argument to st.streamlit_plotly_events.plotly_events.
13
+ *******************************************************
6
14
  よろしくお願いいたします。
7
15
 
8
16
  import pandas as pd
@@ -15,21 +23,16 @@
15
23
  df = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
16
24
  df2 = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
17
25
 
26
+ aaa = st.checkbox('AAA')
18
27
 
28
+ while aaa == True:
29
+ st.write(df)
19
- fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
30
+ fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
20
- fig2 = px.line(df2,x='X', y='Y')
31
+ fig2 = px.line(df2,x='X', y='Y')
21
- fig1.update_layout(clickmode='select')
32
+ fig1.update_layout(clickmode='select')
22
- fig = go.Figure(data=fig1.data + fig2.data)
33
+ fig = go.Figure(data=fig1.data + fig2.data)
23
- selected_points = plotly_events(fig, click_event=False, select_event=True)
34
+ selected_points = plotly_events(fig, click_event=False, select_event=True)
24
-
25
- df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
35
+ df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
26
- st.write(df_final)
36
+ st.write(df_final)
27
-
28
- delete_button = st.button('削除')
29
-
30
- if delete_button == True:
31
37
  st.write('削除後の点は以下')
32
- df_final2 = df2[~df2['X'].isin(df_final['X'])]
38
+ df = df[~df['X'].isin(df_final['X'])]
33
- st.write(df_final2)
34
- else:
35
- st.write('まだ')

6

内容の修正

2021/07/02 10:44

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- streamlitでのグラフの更新
1
+ plotlyのグラフの更新(streamlit)
body CHANGED
@@ -1,7 +1,5 @@
1
- streamlitを使ってグラフ表示をしています。
1
+ 現在、Plotlyでのグラフ表示をしています。
2
- その中で、変更前の数値を使ってグラフを描画しており、
3
- 何か計算(解析)した値がでしだ、前のグラフを計算後の数値を使って更新したいと思っております。
2
+ 当初描画されてグラフをの数値を使って更新したいす。
4
-
5
3
  何か方法などありますでしょうか??
6
4
  ソース内でいうと、最終的に出てきたdf_final2を使ってscatterを描画したい(更新したい)です。
7
5
  ちなみに、px.lineの値はそのままです。

5

修正

2021/07/02 05:51

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- shuusei streamlitでのグラフの更新(計算後の値を使う)
1
+ streamlitでのグラフの更新
body CHANGED
File without changes

4

修正

2021/07/01 05:27

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- streamlitでのグラフの更新(計算後の値を使う)
1
+ shuusei streamlitでのグラフの更新(計算後の値を使う)
body CHANGED
@@ -17,6 +17,7 @@
17
17
  df = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
18
18
  df2 = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
19
19
 
20
+
20
21
  fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
21
22
  fig2 = px.line(df2,x='X', y='Y')
22
23
  fig1.update_layout(clickmode='select')
@@ -25,5 +26,12 @@
25
26
 
26
27
  df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
27
28
  st.write(df_final)
29
+
30
+ delete_button = st.button('削除')
31
+
32
+ if delete_button == True:
33
+ st.write('削除後の点は以下')
28
- df_final2 = df2[~df2['X'].isin(df_final['X'])]
34
+ df_final2 = df2[~df2['X'].isin(df_final['X'])]
29
- st.write(df_final2)
35
+ st.write(df_final2)
36
+ else:
37
+ st.write('まだ')

3

修正

2021/07/01 04:47

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
File without changes
body CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  何か方法などありますでしょうか??
6
6
  ソース内でいうと、最終的に出てきたdf_final2を使ってscatterを描画したい(更新したい)です。
7
+ ちなみに、px.lineの値はそのままです。
7
8
  よろしくお願いいたします。
8
9
 
9
10
  import pandas as pd

2

書式の改善

2021/07/01 04:43

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,6 @@
16
16
  df = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
17
17
  df2 = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
18
18
 
19
- # Select other Plotly events by specifying kwargs
20
19
  fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
21
20
  fig2 = px.line(df2,x='X', y='Y')
22
21
  fig1.update_layout(clickmode='select')

1

ソース追加

2021/07/01 04:41

投稿

Seven_Sea
Seven_Sea

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- streamlitでのループ(計算結果を使ってグラフの更新)
1
+ streamlitでのグラフの更新(計算後の値を使う
body CHANGED
@@ -1,5 +1,29 @@
1
- streamlitを使ってグラフ表示をしているのでが、
1
+ streamlitを使ってグラフ表示をしてい
2
- グラフ内で値を選択後、選択された数値を削除するのですが、
3
- その削除された値を使ってグラフを更新たいなと思っいるのですが
2
+ その中で、変更前の数値を使ってグラフを描画しており
3
+ 何か計算(解析)した値がでしだい、前のグラフを計算後の数値を使って更新したいと思っております。
4
+
4
5
  何か方法などありますでしょうか??
6
+ ソース内でいうと、最終的に出てきたdf_final2を使ってscatterを描画したい(更新したい)です。
5
- よろしくお願いいたします。
7
+ よろしくお願いいたします。
8
+
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
+ import plotly.offline as offline
14
+ import plotly.graph_objects as go
15
+
16
+ df = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
17
+ df2 = pd.DataFrame({'X': [1, 2, 3, 4, 5, 6], 'Y': [1, 2, 3, 4, 5, 6]})
18
+
19
+ # Select other Plotly events by specifying kwargs
20
+ fig1 = px.scatter(df, x='X', y='Y',color_discrete_sequence=["red"])
21
+ fig2 = px.line(df2,x='X', y='Y')
22
+ fig1.update_layout(clickmode='select')
23
+ fig = go.Figure(data=fig1.data + fig2.data)
24
+ selected_points = plotly_events(fig, click_event=False, select_event=True)
25
+
26
+ df_final = df.iloc[[v['pointIndex'] for v in selected_points]]
27
+ st.write(df_final)
28
+ df_final2 = df2[~df2['X'].isin(df_final['X'])]
29
+ st.write(df_final2)