【发布时间】:2020-08-30 23:44:42
【问题描述】:
我有一个简单的 Shiny 应用程序。用户在 textInput 中输入代码,例如:a1、b1、c1 等。
当只列出一个代码时效果很好,但如果用户编写了两个或多个用逗号分隔的代码,则效果不佳。
用户如何输入任意数量的代码?
library(shiny)
ui <- fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
textInput(inputId = "textBox",
label = "Code Search",
placeholder = "Enter codes here seperated by a comma"),
actionButton("textSearchButton", "Generate the Table")
),
fluidRow(
tableOutput("dtOut")
)
)
)
server <- function(input, output) {
df <- data.frame(Code = paste0(letters, 1),
Description = "Something here",
Value = "Some value")
outputFunc <- function(code, df){
# # Dummy data
# code <- c('a1', 'b1', 'c1')
outTbl <- df[df$Code %in% code,]
return(list(outTbl))
}
textSearch <- eventReactive(input$textSearchButton, {
outputFunc(input$textBox, df)
})
output$dtOut <- renderTable({
textSearch()[[1]]
})
}
shinyApp(ui, server)
【问题讨论】:
标签: shiny