Spaces:
Runtime error
Runtime error
Create backupapp.py
Browse files- backupapp.py +37 -0
backupapp.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import plotly.graph_objects as go
|
3 |
+
|
4 |
+
def create_sunburst_plot(df):
|
5 |
+
fig = go.Figure(go.Sunburst(
|
6 |
+
labels=df['labels'],
|
7 |
+
parents=df['parents'],
|
8 |
+
values=df['values'],
|
9 |
+
ids=df['ids'],
|
10 |
+
text=df['text'],
|
11 |
+
hoverinfo="label+value",
|
12 |
+
branchvalues="total",
|
13 |
+
))
|
14 |
+
|
15 |
+
fig.update_layout(margin=dict(t=0, l=0, r=0, b=0))
|
16 |
+
return fig
|
17 |
+
|
18 |
+
data = [
|
19 |
+
{'ids': 'Root', 'labels': 'Root', 'parents': '', 'values': None, 'text': 'Root'},
|
20 |
+
{'ids': 'Hip Surgery', 'labels': 'Hip Surgery', 'parents': 'Root', 'values': 30, 'text': 'Hip Surgery'},
|
21 |
+
{'ids': 'Knee Surgery', 'labels': 'Knee Surgery', 'parents': 'Root', 'values': 40, 'text': 'Knee Surgery'},
|
22 |
+
{'ids': 'CPT1', 'labels': 'CPT1', 'parents': 'Hip Surgery', 'values': 20, 'text': 'CPT1'},
|
23 |
+
{'ids': 'CPT2', 'labels': 'CPT2', 'parents': 'Hip Surgery', 'values': 10, 'text': 'CPT2'},
|
24 |
+
{'ids': 'CPT3', 'labels': 'CPT3', 'parents': 'Knee Surgery', 'values': 25, 'text': 'CPT3'},
|
25 |
+
{'ids': 'CPT4', 'labels': 'CPT4', 'parents': 'Knee Surgery', 'values': 15, 'text': 'CPT4'},
|
26 |
+
]
|
27 |
+
|
28 |
+
df = pd.DataFrame(data)
|
29 |
+
|
30 |
+
# Filter DataFrame using a query parameter
|
31 |
+
def filter_data(df, query):
|
32 |
+
return df.query(query)
|
33 |
+
|
34 |
+
filtered_df = filter_data(df, "parents == 'Root'")
|
35 |
+
|
36 |
+
fig = create_sunburst_plot(filtered_df)
|
37 |
+
fig.show()
|