我有这个带有 anavbarPage
和两个tabPanel
s 的 Shiny App。在第一个选项卡中,我有一个actionLink
初始化modalDialog
包括一个reactable
单元格作为按钮的一个。当我单击表中的按钮时,我想更改我的输入navbarPage
,即tabPanel
从“tabone”更改为“tabtwo”。同时我希望在更改modalDialog
时关闭tabPanel
。我怎么能告诉我modalDialog
关闭呢?
library(Shiny)
library(reactable)
ui = fluidPage(
navbarPage(title = "tabs", id = "nav",
tabPanel(title = "tabone",
actionLink(inputId = "action", "open modalbox")),
tabPanel(title = "tabtwo")
))
server = function(input, output, session){
shinyInput = function(FUN, len, id, labels, ...) {
inputs = character(len)
for (i in seq_len(len)) {
inputs[i] = as.character(FUN(paste0(id, i), label = labels[i], ...))
}
inputs
}
observeEvent(input$action, {
showModal(
modalDialog(
tagList(reactableOutput(outputId = "table"))
))})
output$table = renderReactable({
data = tibble(c = "click to change navbar input") %>%
mutate(c = shinyInput(actionButton, n(), 'id', labels = c, onclick = "Shiny.setInputValue('change', this.innerText)")) %>%
reactable(data = .,
sortable = FALSE,
columns = list(
`c` = colDef(
html = TRUE)
))})
observeEvent(input$change, {
updateTabsetPanel(session = session, inputId = "nav", selected = "tabtwo")
})
}
shinyApp(ui, server)