dynamic - Having two dynamically selectInput in R shiny -


i'm trying create interface allows user choose how many columns focus on, , choose unique value in each column.

the code have not match column value column name. work when pick 1 column. however, no work when there >1 column. 'choose attribute values' resorts first 'choose attribute'. want them compatible.

 library(shiny)   ui<-shinyui(fluidpage(fluidrow(column(width = 4,       numericinput("assets", label = "choose how many attributes produce in map:", value="1"),     uioutput("variants"),     uioutput("variants2")      )   )))  server <-shinyserver( function(input, output, session) {    df<-read.csv("diff_block.csv", stringsasfactors=false, colclasses="character")   df$x<-null     output$variants <- renderui({     numassets <- as.integer(input$assets)       lapply(1:(numassets), function(i) {           list(selectinput ("choose_columns",                          "choose attribute",                          sort(unique(names(df)), decreasing = false),                         selected=""))      })   })      output$variants2 <- renderui({       numassets <- as.integer(input$assets)            lapply(1:(numassets), function(j) {        selectinput ("choose_columns2",                   "choose attribute value",                   sort(unique(df[,input$choose_columns]), decreasing = false),                  selected="")       })     })       })  shinyapp(ui, server)   

you creating sliderinputs same id (selectinput ("choose_columns", ...)). trick use paste0 function create widgets different id's , access values using [[ operator.

library(shiny)   ui<-shinyui(fluidpage(fluidrow(column(width = 4,                                         numericinput("assets", label = "choose how many attributes produce in map:", value="1"),                                       uioutput("variants"),                                       uioutput("variants2")  )   )))  server <-shinyserver( function(input, output, session) {    #df<-read.csv("diff_block.csv", stringsasfactors=false, colclasses="character")   #df$x<-null   df <- iris     # output$variants <- renderui({   #   numassets <- as.integer(input$assets)   #   lapply(1:(numassets), function(i) {   #     list(selectinput ("choose_columns",   #                       "choose attribute",   #                       sort(unique(names(df)), decreasing = false),   #                       selected=""))   #    #   })   # })    output$variants <- renderui({     numassets <- as.integer(input$assets)     lapply(1:(numassets), function(i) {       list(selectinput (paste0("choose_columns", i),                         "choose attribute",                         sort(unique(names(df)), decreasing = false),                         selected=""))      })   })    output$variants2 <- renderui({     numassets <- as.integer(input$assets)        #   lapply(1:(numassets), function(j) {   #        #     selectinput ("choose_columns2",    #                  "choose attribute value",    #                  sort(unique(df[,input$choose_columns]), decreasing = false),   #                  selected="")   #   })   # })      lapply(1:(numassets), function(j) {        var <- input[[paste0("choose_columns", j)]]        selectinput (paste0("choose_attribute", j),                     paste0("choose attribute value of ", var),                    sort(unique(df[ ,var]), decreasing = false),                    selected="")     })   }) })  shinyapp(ui, server)   

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -