Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import streamlit as st
|
3 |
+
import plotly.express as px
|
4 |
+
|
5 |
+
# Set page title
|
6 |
+
st.set_page_config(page_title="d100 Dice Roll Treemap Chart")
|
7 |
+
|
8 |
+
# Define function to roll a d100 dice
|
9 |
+
def roll_dice():
|
10 |
+
return random.randint(1, 100)
|
11 |
+
|
12 |
+
# Roll dice 1000 times and store results
|
13 |
+
rolls = [roll_dice() for _ in range(1000)]
|
14 |
+
|
15 |
+
# Convert rolls to counts and create dictionary
|
16 |
+
counts = {}
|
17 |
+
for roll in rolls:
|
18 |
+
if roll not in counts:
|
19 |
+
counts[roll] = 1
|
20 |
+
else:
|
21 |
+
counts[roll] += 1
|
22 |
+
|
23 |
+
# Create Plotly treemap chart using counts
|
24 |
+
fig = px.treemap(
|
25 |
+
names=[f":game_die: {roll}" for roll in counts.keys()],
|
26 |
+
parents=["Dice Rolls" for _ in counts.keys()],
|
27 |
+
values=list(counts.values()),
|
28 |
+
color=list(counts.keys()),
|
29 |
+
color_continuous_scale="YlOrRd",
|
30 |
+
title="d100 Dice Roll Treemap Chart",
|
31 |
+
)
|
32 |
+
|
33 |
+
# Render chart in Streamlit app
|
34 |
+
st.plotly_chart(fig)
|