Spaces:
Sleeping
Sleeping
File size: 6,144 Bytes
ece1a60 ab6a63c 9beecf3 ece1a60 56abc4b ece1a60 9beecf3 ece1a60 9beecf3 ece1a60 9beecf3 ece1a60 9beecf3 ece1a60 9beecf3 ece1a60 56abc4b ece1a60 9beecf3 ece1a60 56abc4b ece1a60 56abc4b ece1a60 9beecf3 934b31e ece1a60 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
"""
See https://awesome-panel.org/resources/classic_dashboard/
"""
import pathlib
import holoviews as hv
import hvplot.pandas # pylint: disable=unused-import
import pandas as pd
import panel as pn
import param
from holoviews.plotting.util import process_cmap
DASHBOARD_A_PATH="https://cdn.awesome-panel.org/resources/classic_dashboard/dashboard_A.csv"
DASHBOARD_B_PATH="https://cdn.awesome-panel.org/resources/classic_dashboard/dashboard_B.csv"
COLOR_MAPS = hv.plotting.util.list_cmaps()
STYLE = """
body {
margin: 0px;
min-height: 100vh;
overflow-x: hidden;
width: 100%;
background: #f2f2f2;
}
.bk.app-body {
background: #f2f2f2;
color: #000000;
font-family: roboto, sans-serif, Verdana;
}
.bk.app-bar {
background: #212121;
border-color: white;
box-shadow: 5px 5px 20px #9E9E9E;
color: #ffffff;
z-index: 50;
}
.bk.app-container {
background: #ffffff;
border-radius: 5px;
box-shadow: 2px 2px 2px lightgrey;
color: #000000;
}
.bk.app-settings {
background: #e0e0e0;
color: #000000;
}
"""
@pn.cache
def _get_data_a():
return pd.read_csv(DASHBOARD_A_PATH, index_col=0)
@pn.cache
def _get_data_b():
return pd.read_csv(DASHBOARD_B_PATH, index_col=0)
class Dashboard(pn.viewable.Viewer):
"""This application show cases how to build a Classic Dashboard
in Panel.
"""
tool = param.ObjectSelector(label="Tool", default="S1_1", objects=["S1_1", "S2_1"])
variable = param.ObjectSelector(
label="Variable",
default="Cut Distance",
objects=["Cut Distance", "Removed Volume", "Av. uncut chip thickness"],
)
color_map = param.ObjectSelector(default="rainbow", objects=COLOR_MAPS)
view = param.ClassSelector(class_=pn.Column)
def __init__(self, **params):
super().__init__(**params)
self.insert_plot_pane = pn.pane.HoloViews(
self._get_insert_plot, sizing_mode="stretch_width", margin=10, height=300
)
self.edge_plot_pane = pn.pane.HoloViews(
self._get_edge_plot, sizing_mode="stretch_width", margin=10, height=300
)
self.history_plot_pane = pn.pane.HoloViews(
self._update_history_plot, sizing_mode="stretch_width", margin=10, height=300
)
self.view = pn.Column(sizing_mode="stretch_both")
self._init_view()
def _init_view(self):
appbar = pn.Row(
pn.pane.Markdown(
"#### Classic Dashboard in Panel ",
margin=(15, 5, 5, 25),
sizing_mode="stretch_width",
align="center",
),
pn.layout.HSpacer(height=0),
pn.pane.PNG(
"https://panel.holoviz.org/_static/logo_horizontal.png",
width=200,
align="center",
sizing_mode="fixed",
margin=(10, 50, 10, 5),
embed=False,
),
sizing_mode="stretch_width",
css_classes=["app-bar"],
)
settings_bar = pn.Column(
pn.Param(
self,
parameters=["tool", "variable", "color_map"],
widgets={
"tool": {"align": "center", "width": 75, "sizing_mode": "fixed"},
"variable": {
"type": pn.widgets.RadioBoxGroup,
"inline": True,
"align": "end",
"sizing_mode": "stretch_width",
},
},
default_layout=pn.Row,
show_name=False,
sizing_mode="stretch_width",
),
pn.layout.HSpacer(height=0),
sizing_mode="stretch_width",
css_classes=["app-container"],
margin=(50, 25, 25, 25),
)
self.view[:] = [ # pylint: disable=unsupported-assignment-operation
pn.Column(
appbar,
settings_bar,
pn.Row(
pn.Column(
self.insert_plot_pane,
css_classes=["app-container"],
margin=25,
sizing_mode="stretch_both",
),
pn.Column(
self.edge_plot_pane,
css_classes=["app-container"],
margin=25,
sizing_mode="stretch_both",
),
sizing_mode="stretch_both",
min_height=300,
),
pn.Row(
self.history_plot_pane,
css_classes=["app-container"],
margin=25,
min_height=300,
sizing_mode="stretch_both",
),
css_classes=["app-body"],
sizing_mode="stretch_both",
),
pn.layout.HSpacer(height=25),
]
@pn.depends("tool", "variable", "color_map")
def _get_insert_plot(self):
plot_data = _get_data_a().loc[self.tool]
data = [(plot_data["Xo"], plot_data["Yo"], plot_data[self.variable])]
return hv.Path(data, vdims=self.variable).opts(
cmap=self.color_map, color=self.variable, line_width=4, colorbar=True, responsive=True
)
@pn.depends("tool", "variable", "color_map")
def _get_edge_plot(self):
plot_data = _get_data_a().loc[self.tool]
return plot_data.hvplot(
x="Number", y=self.variable, kind="area", alpha=0.6, color=self._color, responsive=True
)
@pn.depends("tool", "color_map")
def _update_history_plot(self):
plot_data = _get_data_b().loc[self.tool]
return plot_data.hvplot(
x="Cut Distance", y="Feed", kind="line", line_width=4, responsive=True
).opts(color=self._color)
@property
def _color(self):
return process_cmap(self.color_map, 1)[0]
if pn.state.served:
pn.extension(raw_css=[STYLE], design="bootstrap")
Dashboard().view.servable()
|