更多輸入類型

案例研究:使用 R 的 Shiny 建置網頁應用程式

Dean Attali

Shiny Consultant

Gapminder 繪圖應用程式

chapter2_3_more_input_types.003.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

滑桿輸入

sliderInput("slider", "Choose a number",
            value = 15, min = 5, max = 20)

chapter2_3_more_input_types.004.png

sliderInput("slider2", "Choose a number",
            value = c(10, 15), min = 5, max = 20)

chapter2_3_more_input_types.006_b.png

str(input$slider2)
num [1:2] 10 15
案例研究:使用 R 的 Shiny 建置網頁應用程式

單選按鈕

radioButtons("radio", "Choose your favorite time of day",
             choices = c("Morning", "Afternoon", "Evening"),
             selected = "Afternoon")

chapter2_3_more_input_types.009.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

下拉式選單輸入

selectInput("select", "Choose your favorite time of day",
            choices = c("Morning", "Afternoon", "Evening"),
            selected = "Afternoon")

chapter2_3_more_input_types.013.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

下拉式選單輸入

selectInput("select", "Choose your favorite time of day",
            choices = c("Morning", "Afternoon", "Evening"),
            selected = "Afternoon")

chapter2_3_more_input_types.014.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

下拉式選單輸入

selectInput("select", "Choose your favorite time of day",
            choices = c("Morning", "Afternoon", "Evening"),
            selected = "Afternoon")

chapter2_3_more_input_types.015.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

下拉式選單輸入

  • 允許多選
selectInput("select", "Choose your favorite time of day",
            choices = c("Morning", "Afternoon", "Evening"),
            selected = c("Afternoon", "Evening"),
            multiple = TRUE)

chapter2_3_more_input_types.016.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

單選按鈕 vs 下拉式選單

  • 單選按鈕
    • 選項少
    • 所有選項皆可見
    • 僅能選一個
  • 下拉式選單
    • 選項可少可多
    • 不易同時看齊所有選項
    • 可多選

chapter2_3_more_input_types.018.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

一起來練習吧!

案例研究:使用 R 的 Shiny 建置網頁應用程式

Preparing Video For Download...