Skip to content

Add/update shiny create templates #1274

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 12 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added an error console which displays errors in the browser's UI. This is enabled by default when running applications locally, and can be disabled with `shiny run --no-dev-mode`. It is not enabled for applications that are deployed to a server. (#1060)

* `shiny create` was updated to include some additional templates as well as an option to choose from the new [templates website](https://shiny.posit.co/py/templates/). (#1273, #1277, #1274)

### Bug fixes

* On Windows, Shiny Express app files are now read in as UTF-8. (#1203)
Expand Down
10 changes: 6 additions & 4 deletions shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,12 @@ def try_import_module(module: str) -> Optional[types.ModuleType]:
# directory. The process for adding new ones is to add your app folder to
# that directory, and then add another entry to this dictionary.
app_template_choices = {
"Basic App": "basic-app",
"Dashboard": "dashboard",
"Multi-page app with modules": "multi-page",
"Custom JavaScript Component": "js-component",
"Basic app": "basic-app",
"Sidebar layout": "basic-sidebar",
"Basic dashboard": "dashboard",
"Intermediate dashboard": "dashboard-tips",
"Navigating multiple pages/panels": "basic-navigation",
"Custom JavaScript component ...": "js-component",
"Choose from the Shiny Templates website": "external-gallery",
}

Expand Down
37 changes: 37 additions & 0 deletions shiny/templates/app-templates/basic-navigation/app-core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import seaborn as sns

# Import data from shared.py
from shared import df

from shiny import App, render, ui

# The contents of the first 'page' is a navset with two 'panels'.
page1 = ui.navset_card_underline(
ui.nav_panel("Plot", ui.output_plot("hist")),
ui.nav_panel("Table", ui.output_data_frame("data")),
footer=ui.input_select(
"var", "Select variable", choices=["bill_length_mm", "body_mass_g"]
),
title="Penguins data",
)

app_ui = ui.page_navbar(
ui.nav_spacer(), # Push the navbar items to the right
ui.nav_panel("Page 1", page1),
ui.nav_panel("Page 2", "This is the second 'page'."),
title="Shiny navigation components",
)


def server(input, output, session):
@render.plot
def hist():
p = sns.histplot(df, x=input.var(), facecolor="#007bc2", edgecolor="white")
return p.set(xlabel=None)

@render.data_frame
def data():
return df[["species", "island", input.var()]]


app = App(app_ui, server)
35 changes: 35 additions & 0 deletions shiny/templates/app-templates/basic-navigation/app-express.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import seaborn as sns

# Import data from shared.py
from shared import df

from shiny.express import input, render, ui

ui.page_opts(title="Shiny navigation components")

ui.nav_spacer() # Push the navbar items to the right

footer = ui.input_select(
"var", "Select variable", choices=["bill_length_mm", "body_mass_g"]
)

with ui.nav_panel("Page 1"):
with ui.navset_card_underline(title="Penguins data", footer=footer):
with ui.nav_panel("Plot"):

@render.plot
def hist():
p = sns.histplot(
df, x=input.var(), facecolor="#007bc2", edgecolor="white"
)
return p.set(xlabel=None)

with ui.nav_panel("Table"):

@render.data_frame
def data():
return df[["species", "island", input.var()]]


with ui.nav_panel("Page 2"):
"This is the second 'page'."
Loading