Selectinput()在Shiny应用程序中使用multiple = TRUE,仅在我连续选择值时响应

时间:2017-10-25 15:06:03

标签: r shiny

我有一个简单的闪亮应用程序,我想创建数据表,它将根据我在selectinput()中选择的名称提供行。虽然当我一个接一个地选择名字(第一,第二,第三......等)时它正常工作但是当我选择名字,然后是第三个名字,然后是第二个等等时它没有响应。有什么建议吗?

nba <- data.frame(
  player = c("James", "Durant", "Curry", "Harden", "Paul", "Wade"), 
  team = c("CLEOH", "GSWOAK", "GSWOAK", "HOUTX", "HOUTX", "CLEOH"),
  day1points = c("25","23","30","41","26","20"), 
  day2points = c("24","25","33","45","26","23"),
  rating=c("1","2","3","4","5","1")
)

ui.r

library(shiny)
library(DT)
ui <- navbarPage(
  title="SADDAS",
           sidebarLayout(
             sidebarPanel(uiOutput("var1_select")),
             mainPanel(tableOutput("reportOutput"))
))

server.r

server <- function(input, output) {
  output$var1_select<-renderUI({
    selectInput("ind_var_select","Select Names", choices =c(as.character(nba[,1] )),multiple = TRUE,selected = nba[1,1])
  })
  output$reportOutput = renderTable(
    {subset(nba[,1:3],player==input$ind_var_select)},
    options = list(scrollX = TRUE)
  )
}

1 个答案:

答案 0 :(得分:0)

试试这个:

library(shiny)

nba <- data.frame(
  player = c("James", "Durant", "Curry", "Harden", "Paul", "Wade"), 
  team = c("CLEOH", "GSWOAK", "GSWOAK", "HOUTX", "HOUTX", "CLEOH"),
  day1points = c("25","23","30","41","26","20"), 
  day2points = c("24","25","33","45","26","23"),
  rating=c("1","2","3","4","5","1")
)

ui <- navbarPage(
  title="SADDAS",
  sidebarLayout(
    sidebarPanel(uiOutput("var1_select")),
    mainPanel(tableOutput("reportOutput"))
  ))

server <- function(input, output) {
  output$var1_select<-renderUI({
    selectInput("ind_var_select","Select Names", choices =c(as.character(nba[,1] )),multiple = TRUE,selected = nba[1,1])
  })
  output$reportOutput = renderTable({
    nba[,1:3][nba$player %in% input$ind_var_select,]
  },
  options = list(scrollX = TRUE)
  )
}

shinyApp(ui, server)