在serverSelecticeInput与server = TRUE之后,与server = FALSE模式相比,它的输入值不可用。有没有办法在serverMode中的以下运行最小示例中获取更新后的selectizeValue?
selectizeOnServer <- TRUE # Switch between TRUE and FALSE and click button to
# see different console outputs after first click on button
library(shiny)
ui <- navbarPage(
title = "navbar",
id = "navbar",
tabPanel(
"panel1",
mainPanel(
actionButton("go", "Go")
)
),
tabPanel(
"panel2",
sidebarLayout(sidebarPanel(
selectizeInput(
inputId = "selectize",
label = "selectize",
choices = NULL,
multiple = TRUE
)
),
mainPanel(textOutput("text"))
)
)
)
server <- function(input, output, session) {
observeEvent(input$navbar ,{
print(input$selectize) # "A" when server = TRUE, NULL when server = FALSE
}, ignoreInit = TRUE)
observeEvent(input$go, {
updateSelectizeInput(session, "selectize", choices = LETTERS, selected = "A", server = selectizeOnServer)
updateNavbarPage(session, "navbar", "panel2")
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
将服务器修改为此可以为您提供预期的行为吗?
server <- function(input, output, session) {
updateSelectizeInput(session, "selectize", choices = LETTERS, server = selectizeOnServer)
observeEvent(input$navbar ,{
print(input$selectize) # "A" when server = TRUE, NULL when server = FALSE
}, ignoreInit = TRUE)
observeEvent(input$go, {
updateSelectizeInput(session, "selectize", choices = LETTERS,selected="E", server = selectizeOnServer)
updateNavbarPage(session, "navbar", "panel2")
})
}