Dropdown menus
You have seen how drop-down menus can be added to a shinyApp. This allows the app user to pick an option out of a list of options, while occupying a small amount of space. This can make for a good UI design if there are already many other features added to the app.
In this exercise, the data has been stored as sleep
and a plot called p
has been stored. The shiny
and tidyverse
libraries have also been loaded. When you have completed the code, you can open the shinyApp in a HTML Viewer for a more complete view.
Este exercício faz parte do curso
Building Dashboards with shinydashboard
Instruções do exercício
- Place a
selectInput()
with two choices called "Plot" and "Table". - Place a
plotOutput()
andtableOutput()
called "plot" and "table". - Add the plot output to the server.
- Add the table output to the server.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
ui <- fluidPage(
titlePanel("Sleeping habits in America"),
# Place a selectInput with two choices, "Plot" and "Table"
___("choice", "Choose an output",
choices = ___),
# Place plot and table outputs called "plot" and "table"
___("plot"), ___)
server <- function(input, output) {
# Add renderPlot
output$plot <- ___({
if(input$choice == "Plot") p
})
# Add renderTable
output$___ <- ___({
if(input$choice == "Table") sleep
}) }
shinyApp(ui, server)