如何从模块内部切换闪亮的选项卡面板? [英] How to switch between shiny tab panels from inside a module?
本文介绍了如何从模块内部切换闪亮的选项卡面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试模块化一个闪亮的应用程序,它有一个按钮,可以使用updateTabsetPanel()在选项卡面板之间进行反应性切换。这在非模块化应用程序中有效,但当使被动反应包含在模块中时则不起作用。我认为这与电池板超出了模块的范围有关。下面是最小的例子(可以工作的非模块化版本和不能工作的模块化版本)。有没有办法让模块与选项卡面板对话?
# Non-modular version
library(shiny)
library(shinydashboard)
ui <- fluidPage(
fluidRow(
column(
width = 12,
tabBox(
id = "tabset2",
type = "tabs",
selected = "1",
tabPanel("T1", value = "1",
fluidRow(
box(width = 9, "Some content here"),
box(width = 3,
actionButton("switchbutton", "Click to swtich")
)
)
),
tabPanel("T2", value = "2",
fluidRow(
box(width = 9, "Some different content here")
)
)
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$switchbutton, {
updateTabsetPanel(session = session,
inputId = "tabset2",
selected = "2")
})
}
shinyApp(ui, server)
# Modular version
library(shiny)
library(shinydashboard)
switcherButton <- function(id) {
ns <- NS(id)
fluidRow(
column(
width = 12,
tabBox(
id = "tabset2",
type = "tabs",
selected = "1",
tabPanel("T1", value = "1",
fluidRow(
box(width = 9, "Some content here"),
box(width = 3,
actionButton(ns("switchbutton"), "Click to switch")
)
)
),
tabPanel("T2", value = "2",
fluidRow(
box(width = 9, "Some different content here")
)
)
)
)
)
}
switcher <- function(input, output, session, parent) {
observeEvent(input$switchbutton, {
updateTabsetPanel(session = session,
inputId = "tabset2",
selected = "2")
})
}
ui <- fluidPage(
switcherButton("switcher1")
)
server <- function(input, output, session) {
callModule(switcher, "switcher1")
}
shinyApp(ui, server)
我
推荐答案
您忘记了将tabBox
ID包装在ns()
中。只需将"tabset2"
替换为ns("tabset2")
这篇关于如何从模块内部切换闪亮的选项卡面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文