Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from bokeh.layouts import column, layout
|
|
| 6 |
from bokeh.models import ColumnDataSource, HoverTool, NumeralTickFormatter, Range1d, Div
|
| 7 |
from bokeh.palettes import Category20, RdYlGn
|
| 8 |
from bokeh.themes import Theme
|
| 9 |
-
from bokeh.embed import components
|
| 10 |
from datetime import datetime
|
| 11 |
|
| 12 |
# Function to generate Bokeh plots
|
|
@@ -120,43 +119,7 @@ def generate_dashboard():
|
|
| 120 |
key = f"{metric}_{suffix}"
|
| 121 |
figures[key] = create_state_figure(f"{'Top' if suffix == 'top' else 'Bottom'} 10 States - {metric}", states, source, metric)
|
| 122 |
|
| 123 |
-
|
| 124 |
-
header = Div(text="<h1 style='text-align: center; color: #0066cc;'>State Statistics Dashboard</h1>", width=1000)
|
| 125 |
-
date_div = Div(text=f"<p style='text-align: center; font-style: italic;'>Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>", width=1000)
|
| 126 |
-
# Layout
|
| 127 |
-
dashboard_layout = layout([
|
| 128 |
-
[header],
|
| 129 |
-
[date_div]] +
|
| 130 |
-
[[figures[f"{metric}_top"]] for metric in state_metrics] +
|
| 131 |
-
[[figures[f"{metric}_bottom"]] for metric in state_metrics] +
|
| 132 |
-
[[change_figures[metric]] for metric in change_metrics]
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
# Custom theme for better appearance
|
| 136 |
-
custom_theme = Theme(json={
|
| 137 |
-
'attrs': {
|
| 138 |
-
'Figure': {
|
| 139 |
-
'background_fill_color': '#f5f5f5',
|
| 140 |
-
'border_fill_color': '#ffffff',
|
| 141 |
-
'outline_line_color': '#444444',
|
| 142 |
-
},
|
| 143 |
-
'Axis': {
|
| 144 |
-
'axis_line_color': '#444444',
|
| 145 |
-
'axis_label_text_font_style': 'bold',
|
| 146 |
-
'axis_label_text_color': '#444444',
|
| 147 |
-
'major_label_text_font_style': 'bold',
|
| 148 |
-
'major_label_text_color': '#444444',
|
| 149 |
-
},
|
| 150 |
-
'Title': {
|
| 151 |
-
'text_font_style': 'bold',
|
| 152 |
-
'text_color': '#444444',
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
})
|
| 156 |
-
|
| 157 |
-
# Generate HTML components
|
| 158 |
-
script, div = components(dashboard_layout, theme=custom_theme)
|
| 159 |
-
return script, div
|
| 160 |
|
| 161 |
# Streamlit application
|
| 162 |
st.set_page_config(page_title="State Statistics Dashboard", layout="wide")
|
|
@@ -164,38 +127,12 @@ st.set_page_config(page_title="State Statistics Dashboard", layout="wide")
|
|
| 164 |
st.title("State Statistics Dashboard")
|
| 165 |
st.markdown(f"<p style='text-align: center; font-style: italic;'>Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>", unsafe_allow_html=True)
|
| 166 |
|
| 167 |
-
# Generate the dashboard
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
# Display the Bokeh plot in Streamlit
|
| 171 |
-
st.components.v1.html(f"""
|
| 172 |
-
<!DOCTYPE html>
|
| 173 |
-
<html lang="en">
|
| 174 |
-
<head>
|
| 175 |
-
<meta charset="UTF-8">
|
| 176 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 177 |
-
<title>State Statistics Dashboard</title>
|
| 178 |
-
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.3.2.min.js"></script>
|
| 179 |
-
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.2.min.js"></script>
|
| 180 |
-
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.2.min.js"></script>
|
| 181 |
-
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-2.3.2.min.css" rel="stylesheet">
|
| 182 |
-
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.2.min.css" rel="stylesheet">
|
| 183 |
-
<link href="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.2.min.css" rel="stylesheet">
|
| 184 |
-
</head>
|
| 185 |
-
<body>
|
| 186 |
-
{div}
|
| 187 |
-
<script>
|
| 188 |
-
{script}
|
| 189 |
-
</script>
|
| 190 |
-
</body>
|
| 191 |
-
</html>
|
| 192 |
-
""", height=1200, scrolling=True)
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
|
| 197 |
-
#
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
# st.write("Hello, Streamlit!")
|
|
|
|
| 6 |
from bokeh.models import ColumnDataSource, HoverTool, NumeralTickFormatter, Range1d, Div
|
| 7 |
from bokeh.palettes import Category20, RdYlGn
|
| 8 |
from bokeh.themes import Theme
|
|
|
|
| 9 |
from datetime import datetime
|
| 10 |
|
| 11 |
# Function to generate Bokeh plots
|
|
|
|
| 119 |
key = f"{metric}_{suffix}"
|
| 120 |
figures[key] = create_state_figure(f"{'Top' if suffix == 'top' else 'Bottom'} 10 States - {metric}", states, source, metric)
|
| 121 |
|
| 122 |
+
return figures, change_figures
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Streamlit application
|
| 125 |
st.set_page_config(page_title="State Statistics Dashboard", layout="wide")
|
|
|
|
| 127 |
st.title("State Statistics Dashboard")
|
| 128 |
st.markdown(f"<p style='text-align: center; font-style: italic;'>Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>", unsafe_allow_html=True)
|
| 129 |
|
| 130 |
+
# Generate the dashboard figures
|
| 131 |
+
figures, change_figures = generate_dashboard()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
# Display the Bokeh plots in Streamlit
|
| 134 |
+
for metric in figures:
|
| 135 |
+
st.bokeh_chart(figures[metric], use_container_width=True)
|
| 136 |
|
| 137 |
+
for metric in change_figures:
|
| 138 |
+
st.bokeh_chart(change_figures[metric], use_container_width=True)
|
|
|