使用 shinydashboard 建立儀表板
Png Kee Seng
Researcher
我們在倫敦的旅遊代理商工作。
觀光客需要住宿。
我們能怎麼幫忙?


header <- dashboardHeader(
title = "Home rental listings")
sidebar <- dashboardSidebar()
body <- dashboardBody()
ui <- dashboardPage(header,
sidebar,
body)
server <- function(input, output) {}
shinyApp(ui, server)
在 body:
fluidRow(
valueBoxOutput(outputId = "count"),
valueBoxOutput(outputId = "prop"),
valueBoxOutput(outputId = "avg"))
在 server:
output$count <- renderValueBox({
valueBox(..., icon = ...)})
output$prop <- renderValueBox(...)
...
在 body:
box(
side = "right", ...,
sliderInput(inputId = "range",
label = "Select price range:",
min = 0,
max = 25000,
value = c(0,25000))
))
更新 server,使用 input$range[1] 與 input$range[2]

在 body:
plotlyOutput("plots",
height = 500,
width = 600)
在 server:
output$plots <- renderPlotly({
...
})

在 body:
selectInput(inputId = "select",
label = "Select group:",
choices = c("Neighbourhood",
"Room Type"))
在 server:
output$plots <- renderPlotly({
if (input$select == ...){plot1}
else if(input$select == ...){plot2}
})
在 body:
box(side = "right", ...,
title = "Welcome to London!",
"...")
更新 body:
tabBox(id = "tabset", ...,
tabPanel("Charts", ...),
tabPanel("Data table", ...)

可以使用 shiny 函式。
在 body:
dataTableOutput("table")
在 server:
output$table <-
renderDataTable(listings)

在 sidebar:
sidebarMenu(
menuItem("Charts", ...),
menuItem("Map", ...))
在 body:
leafletOutput("map",...)
在 server:
output$map <- renderLeaflet(map)
使用 shinydashboard 建立儀表板