Spaces:
Runtime error
Runtime error
import pandas as pd | |
import streamlit as st | |
import plotly.graph_objects as go | |
import time | |
def create_sunburst_plot(df): | |
fig = go.Figure(go.Sunburst( | |
labels=df['labels'], | |
parents=df['parents'], | |
values=df['values'], | |
ids=df['ids'], | |
text=df['text'], | |
hoverinfo="label+value", | |
branchvalues="total", | |
)) | |
fig.update_layout(margin=dict(t=0, l=0, r=0, b=0)) | |
return fig | |
data = [ | |
{'ids': 'Root', 'labels': 'Root', 'parents': '', 'values': None, 'text': 'Root'}, | |
{'ids': 'Hip Surgery', 'labels': 'Hip Surgery', 'parents': 'Root', 'values': 30, 'text': 'Hip Surgery'}, | |
{'ids': 'Knee Surgery', 'labels': 'Knee Surgery', 'parents': 'Root', 'values': 40, 'text': 'Knee Surgery'}, | |
{'ids': 'CPT1', 'labels': 'CPT1', 'parents': 'Hip Surgery', 'values': 20, 'text': 'CPT1'}, | |
{'ids': 'CPT2', 'labels': 'CPT2', 'parents': 'Hip Surgery', 'values': 10, 'text': 'CPT2'}, | |
{'ids': 'CPT3', 'labels': 'CPT3', 'parents': 'Knee Surgery', 'values': 25, 'text': 'CPT3'}, | |
{'ids': 'CPT4', 'labels': 'CPT4', 'parents': 'Knee Surgery', 'values': 15, 'text': 'CPT4'}, | |
] | |
df = pd.DataFrame(data) | |
# Function to update the data | |
def update_data(df): | |
# Here you can add your logic to vary the cost data | |
df['values'] = df['values'] + 5 | |
return df | |
# Create a placeholder for the plot | |
# animate the chart by incrementing the cost values and updating the chart every second. You can adjust the update_data function to customize the variations in the data. | |
# Loop to animate | |
for i in range(10): # Loop for 10 iterations | |
df = update_data(df) | |
fig = create_sunburst_plot(df) | |
#st.plot(create_sunburst_plot(df)) | |
st.plotly_chart(create_sunburst_plot(df)) | |
time.sleep(5) # Sleep for 5 seconds | |