eaglelandsonce commited on
Commit
75cadaa
·
verified ·
1 Parent(s): 5c46e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -4,21 +4,25 @@ import plotly.express as px
4
  import random
5
  import time
6
 
7
- # Placeholder for the Plotly chart
8
- chart_placeholder = st.empty()
9
-
10
  # Specify the radius within which the dots should appear
11
  radius = 5
12
 
 
 
 
 
 
 
13
  while True: # This loop will simulate real-time data updates
14
- # Generate random x and y positions within the specified radius for two dots
15
- new_x1 = random.uniform(-radius, radius)
16
- new_y1 = random.uniform(-radius, radius)
17
- new_x2 = random.uniform(-radius, radius)
18
- new_y2 = random.uniform(-radius, radius)
19
 
20
- # Create new data points with the generated positions for both dots
21
- new_data = pd.DataFrame({'x': [new_x1, new_x2], 'y': [new_y1, new_y2]})
 
 
 
 
22
 
23
  # Create a new Plotly figure for the scatter plot
24
  fig = px.scatter(new_data, x='x', y='y', title="Random Dots within a Radius")
@@ -37,4 +41,4 @@ while True: # This loop will simulate real-time data updates
37
  chart_placeholder.plotly_chart(fig, use_container_width=True)
38
 
39
  # Pause for a moment before updating the chart with new dots
40
- time.sleep(1)
 
4
  import random
5
  import time
6
 
 
 
 
7
  # Specify the radius within which the dots should appear
8
  radius = 5
9
 
10
+ # User input for the number of dots, with initial value set to 5 and max value limited to 10
11
+ num_dots = st.number_input('Number of dots', min_value=1, max_value=10, value=5)
12
+
13
+ # Placeholder for the Plotly chart
14
+ chart_placeholder = st.empty()
15
+
16
  while True: # This loop will simulate real-time data updates
17
+ # Initialize an empty DataFrame for the new data points
18
+ new_data = pd.DataFrame(columns=['x', 'y'])
 
 
 
19
 
20
+ # Generate random x and y positions within the specified radius for the specified number of dots
21
+ for _ in range(num_dots):
22
+ new_x = random.uniform(-radius, radius)
23
+ new_y = random.uniform(-radius, radius)
24
+ # Append the new data point to the DataFrame
25
+ new_data = new_data.append({'x': new_x, 'y': new_y}, ignore_index=True)
26
 
27
  # Create a new Plotly figure for the scatter plot
28
  fig = px.scatter(new_data, x='x', y='y', title="Random Dots within a Radius")
 
41
  chart_placeholder.plotly_chart(fig, use_container_width=True)
42
 
43
  # Pause for a moment before updating the chart with new dots
44
+ time.sleep(1)