首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Rshiny模块应用程序的updateTabsetPanel

带有Rshiny模块应用程序的updateTabsetPanel
EN

Stack Overflow用户
提问于 2020-06-23 21:32:26
回答 1查看 77关注 0票数 0

我用不同的模块和文件开发了一个闪亮的应用程序,我的updateTabsetPanel有一些问题:一个主文件,其中每个选项卡项目都是不同文件中的不同模块。我让模块浏览和注释,它们的调用方式如下:

代码语言:javascript
复制
#### 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)
}

在explore模块中,我有不同的模块,其中一个是我希望在单击按钮后返回的表,感谢模块annotate。因此,目标是在单击操作按钮后返回到探索。但它不起作用。

代码语言:javascript
复制
#### 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")
     }
}

我想知道是什么问题,可能是会议或其他事情,如果你有想法。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-06-23 21:56:34

您的module_annotate_server没有返回值。这就是它不返回任何东西的原因。您需要在包含要返回的数据的模块中创建一个反应式,然后在模块的服务器函数的末尾返回反应式的名称。如下所示:

代码语言:javascript
复制
returnValue <- reactive({
.... some code here ....
})

return(returnValue)

另外,不要把你的callModule放在reactives里面。这就是灾难的秘诀。只需将它们放在主服务器函数的主体中:

代码语言:javascript
复制
exploreVal <- callModule(Module_explore_server, "explore_module", global_data )

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62535986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档