加入多個輸入元件
你可以加入不只一個輸入元件。假設你也希望使用者可以選擇平均睡眠小時數,以及特定的年份。
為了達成這點,在 ui 中,你可以再加入一個 sliderInput(),其值為你關心的年份。
在本練習中,shiny 套件已經替你載入。
本練習屬於課程
使用 shinydashboard 建立儀表板
練習說明
- 在你的 shinyApp 中再加入一個
sliderInput()作為第二個輸入,並將其標籤設為「yearlabel」。 - 將數值範圍設定在
2003到2017之間。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
ui <- fluidPage(
titlePanel("Sleeping habits in America"),
sliderInput("sliderlabel",
"Average hours of sleep",
min = 7.5, max = 11,
value = 8, step = 0.5),
# Add another sliderInput and label the input as "yearlabel"
___(___,
"Year",
# Set the number range to be between 2003 and 2017
___, ___,
value = 2004, step = 1, sep = ""))
server <- function(input, output, session) {
}
shinyApp(ui, server)