is a package that enables the easy generation of bootstrap based dynamic Shiny dashboards.
The core of the package is a common dashboard layout and a number of specialized UI elements (static and reactive) for creating an attractive interface.
This is a container for the title
and any dropdownMenu()
s
the latter are somewhat limited, support “messages”, “notifications”, “tasks” types
Dynamic menus can be generated using dropdownMenuOutput()
and renderMenu()
in the ui and server respectively.
Messages:
Notifications:
Tasks:
This functions in the same way as the sidebarPanel()
in sidebarLayout()
, allowing for the inclusion of inputs and any other html content.
Alternatively, it can also function as a tabPanel()
like menu.
instead of tabsetPanel()
we use sidebarMenu()
,
text and icons are assigned using menuItem()
the panels being activated are contained in the body and not the sidebar
their UI code goes under dashboardBody()
using tabItems()
and tabItem()
.
menuItem()
s are connected to tabItems()
via matching the tabName
arguments.
sidebarMenu()
demos/demo07-1.R
library(tidyverse)
library(shiny)
library(shinydashboard)
ggplot2::theme_set(ggplot2::theme_bw())
d = readr::read_csv(here::here("data/weather.csv"))
d_vars = d |>
select(where(is.numeric)) |>
names()
shinyApp(
ui = dashboardPage(
dashboardHeader(
title="shinydashboard"
),
dashboardSidebar(
selectInput(
"city", "Select a city",
choices = c("Chicago", "Durham", "Sedona", "New York", "Los Angeles")
),
selectInput(
"var", "Select a variable",
choices = d_vars, selected = "humidity"
),
sidebarMenu(
menuItem(
"Temperature",
tabName = "temp",
icon = icon("thermometer-half")
),
menuItem(
"Other",
tabName = "other"
)
)
),
dashboardBody(
tabItems(
tabItem(
"temp",
plotOutput("plot_temp")
),
tabItem(
"other",
plotOutput("plot_other")
)
)
)
),
server = function(input, output, session) {
d_city = reactive({
d |>
filter(city %in% input$city)
})
output$plot_temp = renderPlot({
d_city() |>
ggplot(aes(x=time, y=temp)) +
ggtitle("Temperature") +
geom_line()
})
output$plot_other = renderPlot({
d_city() |>
ggplot(aes(x=time, y=.data[[input$var]])) +
ggtitle(input$var) +
geom_line()
})
}
)
sidebarMenu()
demos/demo07-2.R
library(tidyverse)
library(shiny)
library(shinydashboard)
ggplot2::theme_set(ggplot2::theme_bw())
d = readr::read_csv(here::here("data/weather.csv"))
d_vars = d |>
select(where(is.numeric)) |>
names()
shinyApp(
ui = dashboardPage(
dashboardHeader(
title="shinydashboard"
),
dashboardSidebar(
selectInput(
"city", "Select a city",
choices = c("Chicago", "Durham", "Sedona", "New York", "Los Angeles")
),
selectInput(
"var", "Select a variable",
choices = d_vars, selected = "humidity"
),
sidebarMenuOutput("menu")
),
dashboardBody(
tabItems(
tabItem(
"temp",
plotOutput("plot_temp")
),
tabItem(
"other",
plotOutput("plot_other")
)
)
)
),
server = function(input, output, session) {
output$menu = renderMenu(
sidebarMenu(
menuItem("Temperature", tabName = "temp", icon = icon("thermometer-half")),
menuItem(input$var, tabName = "other")
)
)
d_city = reactive({
d |>
filter(city %in% input$city)
})
output$plot_temp = renderPlot({
d_city() |>
ggplot(aes(x=time, y=temp)) +
ggtitle("Temperature") +
geom_line()
})
output$plot_other = renderPlot({
d_city() |>
ggplot(aes(x=time, y=.data[[input$var]])) +
ggtitle(input$var) +
geom_line()
})
}
)
box()
infoBox()
valueBox()
The color of the various boxes is specified via status
or background
for box()
or color
for the others.
Available options include,
The layout of box elements on a dashboard is controlled by combining fluidRow()
and column()
(as is standard with regular shiny apps)
this layout is based on a page having width of 12 units
column()
and box()
elements take a width
argument using these units
Row-based layout
Column-based layout
Mixed layout
Starting with the app from Demo 05 convert the app to use shinydashboard instead of flexdashboard - we have provided some basic scaffolding shinydashboard code in exercises/ex06.R
and the demo code in exercises/ex06.Rmd
.
Try to preserve the column-based layout and general proportions (i.e. column widths) of the original.
Since shinydashboard does not have a gauge element you can use a value box for everything - If you’re feeling adventurous try using a flexdashboard gauge in your shinydashboard, what happens?
10:00
posit::conf 2023 - Shiny Dashboards