1
下面的代碼顯示了一個帶有兩個選項卡的UI,每個選項卡都包含相同的複選框面板。如果另一個面板更新,我希望一個面板更新,反之亦然。在服務器中使用了觀察功能,但由於某種原因,如果tab1被更改,它只會更新tab2上的checkBoxGroup,但不會以其他方式更改。有沒有人有如何解決這個問題的想法?R Shiny:使用相同的checkBoxGroup兩次
library(shiny)
ui <- shinyUI(
navbarPage("tabs",
tabPanel("tab1",
fluidPage(
sidebarPanel(
checkboxGroupInput("variable", "variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"), selected = list("1"="1"))
)
)),
tabPanel("tab2",
fluidPage(
sidebarPanel(
checkboxGroupInput("variable", "variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"), selected = list("1"="1"))
)
)
)
)
)
server <- function(input, output, session) {
observe({
updateCheckboxGroupInput("variable","variable:",list("1" = "1","2" = "2","3" = "3","4" = "4","5" = "5"),selected=input$variable)
})
}
shinyApp(ui = ui, server = server)
謝謝UnnamedUser! – WhoKnows19