gpt4 book ai didi

r - 当输入更改(例如,选项卡更改)时,我如何告诉我的 modalDialog 自动关闭?

转载 作者:行者123 更新时间:2023-12-04 17:14:13 24 4
gpt4 key购买 nike

我有一个带有 navbarPage 和两个 tabPanel 的 Shiny App。在第一个选项卡中,我有一个 actionLink,它初始化一个 modalDialog,包括一个以单元格作为按钮的 reactable。当我单击表格中的按钮时,我想更改来自 navbarPage 的输入,即将 tabPanel 从“tabone”更改为“tabtwo”。同时,我希望在 tabPanel 更改时关闭 modalDialog。我怎样才能让我的 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)

最佳答案

您可以在 change 按钮的 observeEvent 中添加 removeModal()

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")
removeModal()
})


}

shinyApp(ui, server)

enter image description here

关于r - 当输入更改(例如,选项卡更改)时,我如何告诉我的 modalDialog 自动关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68993936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com