File size: 1,712 Bytes
957da96
d37ee95
957da96
3f2b322
957da96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aba87a1
 
 
3f2b322
 
 
 
957da96
 
 
 
3f2b322
 
 
 
 
957da96
3f2b322
a353a48
957da96
3f2b322
 
 
 
a353a48
3f2b322
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.plotly_chart(fig)
    time.sleep(1)  # Sleep for 1 second