输入

使用 R 构建 Shiny Web 应用

Kaelen Medeiros

Data Scientist

输入示例

Shiny 提供多种可选输入。

滑块输入:选择 1900 到 2000 年的年份

下拉选择:选择狗或猫

数值输入:输入数字,当前为 2

日期范围输入:在 1920 年至今之间输入生日

使用 R 构建 Shiny Web 应用

输入函数

selectInput("inputId", 
            "label", 
            choices = c("A", "B", "C"))
sliderInput("inputId",
            "label",
            value = 1925,
            min = 1900,
            max = 2000)
?dateRangeInput
help(checkboxInput)
使用 R 构建 Shiny Web 应用

输入的使用位置

ui <- fluidPage(
  textInput("name", "输入姓名:"),
  selectInput("animal", "狗还是猫?", choices = c("dogs", "cats")),
  textOutput("greeting"),
  textOutput("answer")
)

server <- function(input, output, session) { output$greeting <- renderText({ paste("您更喜欢狗还是猫,", input$name, "?") }) output$answer <- renderText({ paste("我更喜欢", input$animal, "!") }) }
使用 R 构建 Shiny Web 应用

让我们练习!

使用 R 构建 Shiny Web 应用

Preparing Video For Download...