Spaces:
Runtime error
Runtime error
import streamlit as st | |
import plotly.express as px | |
import pandas as pd | |
import numpy as np | |
# Define the list of game mechanics | |
game_mechanics = ["Action Queue โฑ๏ธ", "Action Retrieval ๐", "Campaign / Battle Card Driven ๐๏ธ", | |
"Card Play Conflict Resolution ๐ณ๐ค", "Communication Limits ๐", | |
"Cooperative Game ๐ค๐ฅ", "Critical Hits and Failures ๐ฅ๐", "Deck Construction ๐ด๐ ๏ธ", | |
"Grid Movement ๐บ๏ธ", "Hand Management ๐๏ธ๐", "Hexagon Grid ๐ณ", "Legacy Game ๐๐ฎ", | |
"Line of Sight ๐", "Modular Board ๐งฉ", "Once-Per-Game Abilities ๐", "Role Playing ๐ญ", | |
"Scenario / Mission / Campaign Game ๐ฏ", "Simultaneous Action Selection ๐ค๐ค", | |
"Solo / Solitaire Game ๐บ", "Storytelling ๐", "Variable Player Powers ๐ฆธโโ๏ธ๐ฆนโโ๏ธ"] | |
# Define a function to generate random values for each game mechanic | |
def generate_values(n): | |
health_points = np.random.randint(50, 100, size=n) | |
coins = np.random.randint(10, 50, size=n) | |
return {"HealthPoints": health_points, "Coins": coins} | |
# Define the Streamlit app | |
def app(): | |
st.title("Game Mechanics Treemap Chart") | |
st.write("This app displays a Treemap chart of game mechanics.") | |
# Generate the data for the chart | |
n = len(game_mechanics) | |
values = generate_values(n) | |
data = pd.DataFrame({ | |
"category": ["Category 1"] * n, | |
"mechanic": game_mechanics, | |
"value": list(values.values()), | |
"HealthPoints": values["HealthPoints"], | |
"Coins": values["Coins"], | |
"description": ["Description"] * n | |
}) | |
data["value"] = data["value"].apply(lambda x: sum(x)) | |
# Draw the chart | |
fig = px.treemap(data, path=["category", "mechanic"], values="value", | |
color="HealthPoints", hover_data=["Coins"]) | |
st.plotly_chart(fig) | |
# Display a download link for the data | |
csv = data.to_csv(index=False) | |
b64 = base64.b64encode(csv.encode()).decode() | |
href = f'<a href="data:file/csv;base64,{b64}" download="game_mechanics.csv">Download CSV</a>' | |
st.markdown(href, unsafe_allow_html=True) | |
if __name__ == '__main__': | |
app() | |