【问题标题】:updateTabsetPanel with a Rshiny modul app带有 R Shiny 模块应用程序的 updateTabsetPanel
【发布时间】:2020-06-23 13:32:26
【问题描述】:

我开发了一个具有不同模块和文件的闪亮应用程序,但我的 updateTabsetPanel 存在一些问题: 一个主文件,其中每个选项卡项都是不同文件中的不同模块。 我让模块 explore 和 annotate 像这样调用:

#### in the main app

server <- function(input,output,session){
  ns <- session$ns

 ## Sidebar panel for inputs
  output$menu <- renderMenu({
  sidebarMenu(id = "tabs_menu",
    menuItem("Input data",tabName ="datafile", icon = icon("file-import")),
    menuItem("Explore", tabName = "explore", icon = icon("microscope")),
    menuItem("Annotate", tabName = "annotate", icon = icon("edit")),
    menuItem("Clusters", tabName = "cluster", icon = icon("asterisk"))
  )})


global_data <- callModule(Module_input_data_server, "data_module" )


#Module explore
  
  observeEvent(input$tabs_menu,{
    if(input$tabs_menu=="explore"){
      callModule(Module_explore_server, "explore_module", global_data )
    }
  }, ignoreNULL = TRUE, ignoreInit = TRUE)

 #Module annotate
 observeEvent(input$tabs_menu,{
   if(input$tabs_menu=="annotate"){
     callModule(Module_annotate_server, "annotate_module",global_data)
   }
 }, ignoreNULL = TRUE, ignoreInit = TRUE)
}

在探索模块中,我有不同的模块,其中一个是我想在单击按钮后通过模块注释返回的表格。所以目标是点击动作按钮后返回探索。但它不起作用。

#### in the annotate module the observe event for the click button

Module_annotate_server  <- function(input, output,session, rv) {
  req(rv$data)

  ns <- session$ns
  observeEvent(input$annotateButton,{
    req(rv$data)
    print("how")
    # if(is.null(rv$secure)){
    if(!is.null(input$newCol) && input$newCol != "") {
      print("how1")
      new.column <- rep(NA,nrow(rv$data))
      rv$data <- cbind(rv$data, new.column)
      colnames(rv$data)[ncol(rv$data)] <- input$newCol
      rv$annotationCol <- input$newCol
    } else if(!is.null(input$annotationCol) && input$annotationCol != "") {
      print("how2")
      rv$annotationLabels <- unique(rv$data[,input$annotationCol])
      rv$annotationCol <- input$annotationCol
    }
    if(length(input$labelsList)>0) {
      print("how3")
      new.labels <- unlist(strsplit(input$labelsList, "\\s*,\\s*"))
      if(length(new.labels)>0) {
        rv$annotationLabels <- c(input$annotationLabels, new.labels)
      }
    }
    if(is.null(rv$annotationLabels) || length(rv$annotationLabels) == 0) {
      showNotification("Some labels must be provided.", type ="error", duration = NULL)
    } else {
      # Move to the Explore tab
       updateTabsetPanel(session , "tabs_menu", selected = "explore")
     }
}

如果您有想法,我想知道问题可能是会话或其他问题。

谢谢!

【问题讨论】:

    标签: r shiny shinyapps


    【解决方案1】:

    您的module_annotate_server 没有返回值。这就是为什么它不返回任何东西。您需要在包含您要返回的数据的模块中创建一个响应式,然后在模块的服务器函数的末尾返回响应式的名称。像这样的:

    returnValue <- reactive({
    .... some code here ....
    })
    
    return(returnValue)
    

    另外,不要将您的 callModules 放在反应器中。这是灾难的秘诀。简单地把它们放在主服务器函数的主体中:

    exploreVal <- callModule(Module_explore_server, "explore_module", global_data )
    

    然后您可以使用exploreVal() 引用模块的返回值。为您的annotate_module 做类似的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 2015-04-15
      相关资源
      最近更新 更多