仅当按下操作按钮时,R闪亮的更新筛选器

时间:2019-07-10 20:01:30

标签: shiny action-button

我正在尝试创建一个仅在单击按钮时才更新SelectInput和PickerInput的操作按钮。

library(shiny)    

shinyUI(basicPage(

v1 <- c("a","b","c")
v2 <- 1:3
data <- data.frame(v1,v2)

pickerInput("v1",label = "v1",""),
uiOutput("secondSelection"),
actionButton("go", "Update")

))


shinyServer(function(input, output) {

output$secondSelection <- renderUI({
pickerInput("v2", "Variable 2:","")
})

v1vals <- reactiveValues(v1)
v2vals <- reactiveValues(v2)

observe({

if(input$go > 0) {
v1vals$v1<- levels(data$v1)
v2vals$v2<- levels(data$v2)
}

v1vals$v1<- input$v1
v2vals$v2<- input$v2
})

output$text <- renderText({values$variable})

observe( observeEvent(input$go, {

updatePickerInput(session,"v1",label = "variable 1",
                choices = levels(data$v1),
                selected = levels(data$v1), multiple = TRUE)
}))

observe( observeEvent(input$go, {

updatePickerInput(session, "v2", choices =             
as.character(unique(data[data$v1==input$v1,"v2"])),
options = list(`actions-box` = TRUE), 
multiple = TRUE, selected =levels(data$v2))

}))

})

我希望v1和v2的默认选择是所有级别,并且过滤器仅在单击操作按钮时才更新应用程序的其余部分。

0 个答案:

没有答案