我的数据框如下
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()
})
}
答案 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
})