Selectinput没有采用给定的值,并且不能正确更新表

时间:2019-06-14 21:32:29

标签: r shiny

我的数据框如下

x <- data.frame(CategoryA=c("First", "Second",
                                   "Third" ),
                CategoryB=c("First", "Second",
                                   "Third"),
                Frequency=c(10,15,5))

我使用的闪亮应用程序应将CategoryA值用作输入,并根据此选择更新数据表。第一个问题是selectInput()接受1,2,3而不是“ First”,“ Second”,“ Third”作为输入,并且当然不能正确更新表。

#ui.r
pageWithSidebar(
  headerPanel('k-means '),
  sidebarPanel(
    uiOutput("inv")
  ),
  mainPanel(
    dataTableOutput("tab1")
  )
)
#server.r
library(shiny)
library(tidyverse)
library(DT)
function(input, output, session) {
  output$inv<-renderUI({
    selectInput("tow", label ="Suburb", 
                choices = c(unique(x$CategoryA)),
                multiple = T)
  })


  datasett<-reactive({
    tmp1 <- x %>% 
      filter(x[,1] == input$tow )
    tmp1
  })
  output$tab1<-renderDataTable({
    datasett()
  })
}

1 个答案:

答案 0 :(得分:1)

您需要stringsAsFactors = F-

x <- data.frame(CategoryA=c("First", "Second",
                                   "Third" ),
                CategoryB=c("First", "Second",
                                   "Third"),
                Frequency=c(10,15,5), stringsAsFactors = F)

还-

datasett < -reactive({
    tmp1 <- x %>% 
      filter(CategoryA %in% input$tow )
    tmp1
  })