【发布时间】:2019-08-22 01:53:20
【问题描述】:
我在下面的代码中有 selectizeInput 中的依赖项。
我正在尝试更新两个输入,但出现问题并且只更新第一个值
有任何想法吗?
谢谢帮助
library(shiny)
library(DT)
ui <- navbarPage(
title = "Interaction with Table Cells", id = "x0",
tabPanel(
"Table", DT::dataTableOutput("x1"),
selectizeInput("s1", "speed", choices = cars %>% pull(speed) %>% unique()),
uiOutput("s2")
)
)
server <- function(session, input, output) {
# add CSS style 'cursor: pointer' to the 0-th column (i.e. row names)
output$x1 <- DT::renderDataTable({
datatable(
cars,
selection = "none", class = "cell-border strip hover"
) %>% formatStyle(0, cursor = "pointer")
})
output$s2 <- renderUI({
selectizeInput("s2", "dist", choices = cars %>% filter(speed == input$s1) %>%
pull(dist) %>% unique())
})
observeEvent(input$x1_cell_clicked, {
info <- input$x1_cell_clicked
# do nothing if not clicked yet, or the clicked cell is not in the 1st column
if (is.null(info$value) || info$col != 0) {
return()
}
updateSelectizeInput(session, "s1", selected = cars[info$row, "speed"])
updateSelectizeInput(session, "s2", selected = cars[info$row, "dist"])
})
}
shinyApp(ui, server)
【问题讨论】: