-
Notifications
You must be signed in to change notification settings - Fork 107
docs(layout_columns): Add example app #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
576793b
3872b52
0dc784a
9363d9a
efcd7e1
475e76b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from model_plots import * # model plots and cards | ||
|
||
from shiny import App, Inputs, Outputs, Session, render, ui | ||
|
||
app_ui = ui.page_fluid( | ||
ui.panel_title(ui.h2("Model Dashboard")), | ||
ui.div("Using", ui.code("ui.layout_columns()"), ".", class_="mb-2"), | ||
ui.layout_columns( | ||
card_loss, | ||
card_acc, | ||
card_feat, | ||
col_widths=(5, 7, 12), | ||
# row_heights=(2, 3), | ||
# height="700px", | ||
), | ||
) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session): | ||
@render.plot | ||
def loss_over_time(): | ||
return plot_loss_over_time() | ||
|
||
@render.plot | ||
def accuracy_over_time(): | ||
return plot_accuracy_over_time() | ||
|
||
@render.plot | ||
def feature_importance(): | ||
return plot_feature_importance() | ||
|
||
|
||
app = App(app_ui, server) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from shiny import ui | ||
|
||
|
||
def plot_loss_over_time(): | ||
epochs = np.arange(1, 101) | ||
loss = 1000 / np.sqrt(epochs) + np.random.rand(100) * 25 | ||
|
||
fig = plt.figure(figsize=(10, 6)) | ||
plt.plot(epochs, loss) | ||
plt.xlabel("Epochs") | ||
plt.ylabel("Loss") | ||
return fig | ||
|
||
|
||
def plot_accuracy_over_time(): | ||
epochs = np.arange(1, 101) | ||
accuracy = np.sqrt(epochs) / 12 + np.random.rand(100) * 0.15 | ||
accuracy = [np.min([np.max(accuracy[:i]), 1]) for i in range(1, 101)] | ||
|
||
fig = plt.figure(figsize=(10, 6)) | ||
plt.plot(epochs, accuracy) | ||
plt.xlabel("Epochs") | ||
plt.ylabel("Accuracy") | ||
return fig | ||
|
||
|
||
def plot_feature_importance(): | ||
features = ["Product Category", "Price", "Brand", "Rating", "Number of Reviews"] | ||
importance = np.random.rand(5) | ||
|
||
fig = plt.figure(figsize=(10, 6)) | ||
plt.barh(features, importance) | ||
plt.xlabel("Importance") | ||
return fig | ||
|
||
|
||
card_loss = ui.card( | ||
ui.card_header("Loss Over Time"), | ||
ui.output_plot("loss_over_time"), | ||
) | ||
|
||
card_acc = ui.card( | ||
ui.card_header("Accuracy Over Time"), | ||
ui.output_plot("accuracy_over_time"), | ||
) | ||
|
||
card_feat = ui.card( | ||
ui.card_header("Feature Importance"), | ||
ui.output_plot("feature_importance"), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll also be interesting to see how this example renders in the docs, I'm specifically curious whether the viewer will have a height large enough to make this a good experience. Partially for that reason, we may want to turn down the heights on the plots (or maybe use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'm also worried about how this will render in the docs. It's hard to know in advance; I don't think I can preview it locally. I specifically used |
Uh oh!
There was an error while loading. Please reload this page.