以下逻辑从UI提供Dropdown并且运行良好。
带R闪亮的动态textInput(USer可以输入任何文字) 需要帮助:现在我希望“col_a4”上的用户输入STRING匹配用户输入字符串,而不是下拉“col_a4”。
在我的作品中使用了闪亮的仪表板和DT库。有什么方法可以在UI中包含搜索选项以在-col_a4
中搜索 ###### UI.R
library(shiny)
library(shinydashboard)
library(DT)
ui <- shinyUI(fluidPage(titlePanel("Demo"),selectInput("dataset", "Choose a dataset:",choices = c("Book1", "Book2", "Book3")),
column(width=2,uiOutput("col_a1")),
column(width=2,uiOutput("col_a2")),
column(width=2,uiOutput("col_a3")),
column(width=2,uiOutput("col_a4")),
div(style="display: inline-block;vertical-align:top; width: 8px;",HTML("<br>")),
downloadButton("downloadData", "Click Me"),
uiOutput("dt")
))
###### server.R
library(shiny)
library(DT)
server = shinyServer(function(input,output){
global <- reactiveValues(refresh = FALSE)
datasetInput <- reactive({
switch(input$dataset,
"Book1" = Book1,
"Book2" = Book2,
"Book3" = Book3)
})
output$Dataset1 <- renderDataTable({
data=datasetInput()
})
output$col_a1 = renderUI({
selectInput("col_a1", "Select col_a1:", datasetInput()$col_a1,selectize = TRUE,multiple = T)
})
output$col_a2 = renderUI({
selectInput("col_a2", "Select col_a2:", datasetInput()$col_a2,selectize = TRUE,multiple = T)
})
output$col_a3 = renderUI({
selectInput("col_a3", "Select col_a3:", datasetInput()$col_a3,selectize = TRUE,multiple = T)
})
output$col_a4 = renderUI({
selectInput("col_a4", "Select col_a4:", datasetInput()$col_a4,selectize = TRUE,multiple = T)
})
output$Counter = renderText(
{
output$Clicked = renderText(0)
isolate(global$refresh <- FALSE)
filter = datasetInput()$col_a1%in%input$col_a1 &
datasetInput()$col_a2%in%input$col_a2 &
datasetInput()$col_a3%in%input$col_a3 &
datasetInput()$col_a4%in%input$col_a4
DataFilter1 = paste("Total Number of Records",nrow(subset(datasetInput(),
filter)))
}
)
observeEvent(input$Click,{
output$Clicked = renderText(1)
isolate(global$refresh <- TRUE)
output$Table = DT::renderDataTable(
{
input$Click
filter = datasetInput()$col_a1%in%input$col_a1 &
datasetInput()$col_a2%in%input$col_a2 &
datasetInput()$col_a3%in%input$col_a3 &
datasetInput()$col_a4%in%input$col_a4
DataFilter = subset(datasetInput(),filter)
})
output$Datasetaa1 <- renderDataTable({
data=Table()
})
output$mytable11 <- DT::renderDataTable({
DT::datatable(Datasetaa1[, input$show_vars, drop = FALSE])
})
output$dt <- renderUI({if(global$refresh == FALSE) return()
dataTableOutput('mytable11')})
})
myout = reactive({
filter = datasetInput()$col_a1%in%input$col_a1 &
datasetInput()$col_a2%in%input$col_a2 &
datasetInput()$col_a3%in%input$col_a3 &
datasetInput()$col_a4%in%input$col_a4
DataFilter = subset(datasetInput(),filter)
})
output$downloadData <- downloadHandler(
filename=function() {
paste('data-', Sys.Date(), '.csv', sep='')
},
content = function(file) {
write.csv(myout(),file)
},
contentType = "text/plain"
)
})