Having difficulty getting an actionButton in a nested Shiny module to work

家住魔仙堡 提交于 2021-01-28 06:31:00

问题


In the following modularized shiny app the insertBtn_outer button works okay, but I am struggling to get the insertBtn_inner button to work. Many thanks for any insights that could help to resolve my issue.

library(shiny)

innerUI <- function(id){
  ns <- NS(id)
  actionButton(ns('insertBtn_inner'), 'Insert')
}

inner <- function(input,output,session){
  observeEvent(input$insertBtn_inner, {
    showModal(modalDialog(
      title = 'Debug message',
      paste0('The inner button works'),
      easyClose = TRUE,
      footer = NULL
    ))})
}

outerUI <- function(id){
  ns <- NS(id)
  tagList(
    actionButton(ns('insertBtn_outer'), 'Insert'),
    br(),
    tabsetPanel(id=ns('tabset'), type = 'tabs',
                innerUI('inner1')))
}

outer <- function(input,output,session){
  callModule(inner,'inner1')
  observeEvent(input$insertBtn_outer, {
    showModal(modalDialog(
      title = 'Debug message',
      paste0('The outer button works'),
      easyClose = TRUE,
      footer = NULL))})
}  


ui <- shiny::navbarPage('test_app',
                        shiny::tabPanel('Tab Panel',
                                        outerUI('test')))

server <- function(input, output) {
  callModule(outer,'test')
}

shinyApp(ui = ui, server = server)

回答1:


Inside a tabsetPanel, you must use one or more tabPanel. In addition you have to call the innerUI with ns, that is innerUI(ns('inner1')).

outerUI <- function(id){
  ns <- NS(id)
  tagList(
    actionButton(ns('insertBtn_outer'), 'Insert'),
    br(),
    tabsetPanel(tabPanel("XXX", innerUI(ns('inner1'))), 
                id=ns('tabset'), type = 'tabs')
  )
}


来源:https://stackoverflow.com/questions/56237190/having-difficulty-getting-an-actionbutton-in-a-nested-shiny-module-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!