awacke1 commited on
Commit
d29f19d
ยท
1 Parent(s): a8c664d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import plotly.express as px
5
+
6
+ st.title('Random Dice Games for STEM Math and Data Science')
7
+
8
+ # Get user input for the number of dice rolls
9
+ num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000000, 1000)
10
+
11
+ # Generate dice rolls
12
+ rolls = np.random.randint(1, 7, num_rolls)
13
+
14
+ # Count the number of occurrences of each roll
15
+ roll_counts = pd.Series(rolls).value_counts().sort_index()
16
+
17
+ # Create a sunburst chart of the roll counts
18
+ fig = px.sunburst(
19
+ names=[f'Roll {i}' for i in roll_counts.index],
20
+ parents=['Dice Rolls'] * 6,
21
+ values=roll_counts.values,
22
+ color=[f'Roll {i}' for i in roll_counts.index],
23
+ color_discrete_sequence=px.colors.qualitative.Dark24,
24
+ maxdepth=2
25
+ )
26
+
27
+ # Customize the chart layout
28
+ fig.update_layout(
29
+ title='Dice Roll Distribution',
30
+ margin=dict(l=20, r=20, t=40, b=20),
31
+ width=800,
32
+ height=600
33
+ )
34
+
35
+ # Add UI controls to modify the chart
36
+ show_labels = st.checkbox('Show Labels', value=True)
37
+ if not show_labels:
38
+ fig.update_traces(textinfo='none')
39
+ fig.show()
40
+
41
+ # Allow user to download roll data as CSV file
42
+ if st.button('Download Roll Data as CSV'):
43
+ roll_data = pd.DataFrame({
44
+ 'Roll': rolls,
45
+ 'Count': np.ones(num_rolls)
46
+ })
47
+ st.download_button(
48
+ label='Download CSV',
49
+ data=roll_data.to_csv(index=False),
50
+ file_name='roll_data.csv',
51
+ mime='text/csv'
52
+ )