r 在Shiny中选择和多个selectInput

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 在Shiny中选择和多个selectInput相关的知识,希望对你有一定的参考价值。

library(shiny)
library(ggplot2)
library(dplyr)
library(DT)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))
all_studios <- sort(unique(movies$studio))

# UI
ui <- fluidPage(
    sidebarLayout(
    
    # Input(s)
    sidebarPanel(
      selectInput(inputId = "studio",
                  label = "Select studio:",
                  choices = all_studios,
                  selected = "20th Century Fox",
                  selectize = TRUE,
                  multiple = TRUE)
      
    ),
    
    # Output(s)
    mainPanel(
      DT::dataTableOutput(outputId = "moviestable")
    )
  )
)

# Server
server <- function(input, output) {
  
  # Create data table
  output$moviestable <- DT::renderDataTable({
    req(input$studio)
    movies_from_selected_studios <- movies %>%
      filter(studio %in% input$studio) %>%
      select(title:studio)
    DT::datatable(data = movies_from_selected_studios, 
                  options = list(pageLength = 10), 
                  rownames = FALSE)
  })
  
}

# Create a Shiny app object
shinyApp(ui = ui, server = server)

以上是关于r 在Shiny中选择和多个selectInput的主要内容,如果未能解决你的问题,请参考以下文章

R Shiny - 如何在 selectInput 中显示选择标签

使用 R Shiny 进行多重线性回归 (SelectInput --> multiple=TRUE)

R Shiny:将多个连续的反应传递给 selectInput

基于选项卡面板选择在 R Shiny 中显示/隐藏 selectinput

未选择值时如何更改 R Shiny 'selectInput' 值选择显示空间背景颜色?

selectInput 选择依赖于 R Shiny Flexdashboard 的另一个 selectInput