below logic gives dropdown's ui , working well.
dynamic textinput r shiny ( user can enter text ) need help: want user input string on "col_a4" match user input string rather drop down on"col_a4".
used shiny dashboard , dt library in work. there way can include search option in ui search in -col_a4
###### ui.r library(shiny) library(shinydashboard) library(dt) ui <- shinyui(fluidpage(titlepanel("demo"),selectinput("dataset", "choose 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" ) })
Comments
Post a Comment