Skip to content

Commit 8ad1817

Browse files
authored
docs(layout_columns): Add example app (#903)
1 parent b8a2316 commit 8ad1817

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from model_plots import * # model plots and cards
2+
3+
from shiny import App, Inputs, Outputs, Session, render, ui
4+
5+
app_ui = ui.page_fluid(
6+
ui.panel_title(ui.h2("Model Dashboard")),
7+
ui.markdown("Using `ui.layout_columns()` for the layout."),
8+
ui.layout_columns(
9+
card_loss,
10+
card_acc,
11+
card_feat,
12+
col_widths={"sm": (5, 7, 12)},
13+
# row_heights=(2, 3),
14+
# height="700px",
15+
),
16+
)
17+
18+
19+
def server(input: Inputs, output: Outputs, session: Session):
20+
@render.plot
21+
def loss_over_time():
22+
return plot_loss_over_time()
23+
24+
@render.plot
25+
def accuracy_over_time():
26+
return plot_accuracy_over_time()
27+
28+
@render.plot
29+
def feature_importance():
30+
return plot_feature_importance()
31+
32+
33+
app = App(app_ui, server)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
4+
from shiny import ui
5+
6+
7+
def plot_loss_over_time():
8+
epochs = np.arange(1, 101)
9+
loss = 1000 / np.sqrt(epochs) + np.random.rand(100) * 25
10+
11+
fig = plt.figure(figsize=(10, 6))
12+
plt.plot(epochs, loss)
13+
plt.xlabel("Epochs")
14+
plt.ylabel("Loss")
15+
return fig
16+
17+
18+
def plot_accuracy_over_time():
19+
epochs = np.arange(1, 101)
20+
accuracy = np.sqrt(epochs) / 12 + np.random.rand(100) * 0.15
21+
accuracy = [np.min([np.max(accuracy[:i]), 1]) for i in range(1, 101)]
22+
23+
fig = plt.figure(figsize=(10, 6))
24+
plt.plot(epochs, accuracy)
25+
plt.xlabel("Epochs")
26+
plt.ylabel("Accuracy")
27+
return fig
28+
29+
30+
def plot_feature_importance():
31+
features = ["Product Category", "Price", "Brand", "Rating", "Number of Reviews"]
32+
importance = np.random.rand(5)
33+
34+
fig = plt.figure(figsize=(10, 6))
35+
plt.barh(features, importance)
36+
plt.xlabel("Importance")
37+
return fig
38+
39+
40+
card_loss = ui.card(
41+
ui.card_header("Loss Over Time"),
42+
ui.output_plot("loss_over_time"),
43+
full_screen=True,
44+
)
45+
46+
card_acc = ui.card(
47+
ui.card_header("Accuracy Over Time"),
48+
ui.output_plot("accuracy_over_time"),
49+
full_screen=True,
50+
)
51+
52+
card_feat = ui.card(
53+
ui.card_header("Feature Importance"),
54+
ui.output_plot("feature_importance"),
55+
full_screen=True,
56+
)

0 commit comments

Comments
 (0)