r - Shiny multiple dynamic subsetting -


i trying make app in shiny dynamically subsetting data-set 3 times users input. let's assume dataset

number<- c(10, 20, 30 , 40, 50 ,60, 70, 80, 90,100,110,120,130,140) att1 <- c('a','a','a','a','a','a','a','b','b','b','b','b','b','b') att2 <- c('c','c','c','d','d','d','d','e','e','e','g','g','g','g') index<-c('i1','i2','i3','i4', 'i5','i6','i7','i8','i9','i10', 'i11','i12','i13','i14') df <- data.frame(number, att1 , att2,index) 

what want create dropdown menu gives choices or b att1 choice reacts second drop down choices of att2 displayed subsetted choice att1. depending on choice user last drop down give him choices index choose. after choice of index dataframe have return numbers indicated index , number used in next steps.

# # shiny web application. can run application clicking # 'run app' button above. # # find out more building applications shiny here: # #    http://shiny.rstudio.com/ #  library(shiny) library(data.table) # define ui application draws histogram ui <- fluidpage(    # application title   titlepanel("app"),    sidebarlayout(     sidebarpanel(       selectinput("att1", "choose att1",choices= c(as.character(unique(df$att1))  )),       uioutput("c")),     # show plot of generated distribution     mainpanel( dt::datatableoutput("table")      )   ) )  # define server logic required draw histogram server <- function(input, output) {   number<- c(10, 20, 30 , 40, 50 ,60, 70, 80, 90,100,110,120,130,140)   att1 <- c('a','a','a','a','a','a','a','b','b','b','b','b','b','b')   att2 <- c('c','c','c','d','d','d','d','e','e','e','g','g','g','g')   index<-c('i1','i2','i3','i4', 'i5','i6','i7','i8','i9','i10', 'i11','i12','i13','i14')   df <- data.frame(number, att1 , att2,index)     selecteddata <- reactive({     ddata<-subset(df,att1==input$att1)   })    output$c<-renderui({selectinput("att2", "choose att2",choices= c(as.character(unique(selecteddata()$att2)) ))})   selecteddata2 <- reactive({     vdata<-subset(selecteddata(),att2==input$c)     vdata<-as.data.frame(vdata)     vdata   })    output$table <- dt::renderdatatable({     head(selecteddata2(), n = 10)   })    }  # run application  shinyapp(ui = ui, server = server) 

this got far problem how can use reactive dataset second time in reactive expression , output first 2 attributes null. trying solve days, thoughts?

there specific shiny function update content of selectinput: updateselectinput().

if used inside observe can used trying do:

server <- function(input, output, session) {      observe({         input$att1          x <- df[df$att1 == input$att1, 'att2']         xs <- as.character(unique(x))         updateselectinput(session, 'att2', choices = xs)     })      selecteddata <- reactive({         df[df$att2 == input$att2, ]     })      output$table <- dt::renderdatatable({         head(selecteddata(), n = 10)     })         } 

here ui completeness

ui <- fluidpage(      # application title     titlepanel("app"),      sidebarlayout(         sidebarpanel(             selectinput("att1", "choose att1",choices = as.character(unique(df$att1))  ),             selectinput("att2", "choose att2",choices = null, selected = 1)             ),         # show plot of generated distribution         mainpanel( dt::datatableoutput("table")          )     ) ) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -