首页 > 解决方案 > 闪亮模块的两个问题

问题描述

这是一个最小的例子。我正在尝试模块化现有应用程序以分离不同的分析问题。每个问题都有一个用于输入的侧边栏面板和一个用于输出的主面板。我在为输入设置侧边栏面板时遇到两个问题。我将有两个按钮在第一个被选中后交换。此操作位于模块服务器代码中,需要读取所选分析(导航栏中的选项卡标签),然后对读取的值进行操作。我收到此问题的错误:警告:== 中的错误:比较 (1) 仅适用于原子和列表类型 44:[/appsdata/home/wk211a/Projects/vrat4/minexample.R#61] 1:runApp

第二个问题是我无法在第一个选项卡中显示简单的 renderText 消息。

这是代码:

##### Test Example

##### Setup VRAT App

ContCurrentSideBarPanelUI <- function(id){
  
  ns <- NS(id)
  
  tagList(
    
    tabsetPanel(
      id = "sbpcontin",
      tabPanel(
        "Setup",
        value = "setup_Cont_Curr",
        textOutput(ns("result"))
      ),
      tabPanel(
        "Verification",
        value = "verify_Cont_Curr"
      ),
      tabPanel(
        "Process",
        value = "process_Cont_Curr"
      ),
      tabPanel(
        "Design",
        value = "req_Cont_Curr"
      ),
      tabPanel(
        "Risk Analysis",
        value = "risk_Cont_Curr",
      ),
      tabPanel(
        "Guardbanding",
        value = "gb_Cont_Curr"
      ),
      tabPanel(
        "Sampling",
        value = "sample_Cont_Curr"
      ),
      tabPanel(
        "Decon",
        value = "decon_Cont_Curr"
      )
    )
  )
}

ContCurrentSideBarPanelServer <- function(id,appTabs,Maincount){
  moduleServer(
    id,
    function(input,output,session){
      observe({
        output$result <- renderText({
          paste0("Here I am ", 63)
        })
     })
      
      observe({
        if (appTabs == "cont_Data" ) {
          showElement(id = "goButton")
          hideElement(id = "goButton3")
        }
      })
      x <- 93
      return(x)
    }
  )
}

VRATui <- shinyUI(
  
  ### Start Navbar Page
  
  navbarPage(
    title = "Test Tool",
    selected = "Introduction",
    fluid=TRUE,
    
    ### Start App Tab panel
    
    tabsetPanel(id = "appTabs",
                type = "pills",
                
                 ### Start the tab panel for the Data Screen
                
                tabPanel(
                  value = "cont_Data",
                  title = "Continuous Data",
                  
                  ### Start the Continuous sidebar layout
                  
                  sidebarLayout(
                    
                    ### Start the Continuous sidebar panel
                    
                    sidebarPanel(
                      id = "cndsp",
                      width = 3,
                      style = "overflow-y:scroll; max-height: 80vh",
                      
                      h4("Analysis of Current Data"),
                      hr(style="border-color: darkblue;"),
                      
                      conditionalPanel(
                        condition = "input.appTabs == 'cont_Data' && input.Maincont == 'currentCont'",
                        
                        ### Submit setup for analysis
                        
                        actionButton(inputId = "goButton", label = "Start Current Analysis", width = '100%'),
                        actionButton(inputId = "goButton3", label = "Update Current Analysis", width = '100%'),
                        
                        ### Sidebar Panel Tabs
                        
                        ContCurrentSideBarPanelUI("ContCurrentSideBarPanel")
                      ),
                      
                    ### End Continuous Data Analysis sidebar panel 
                    
                  ),  
                      mainPanel()
                  
                  ### End the sidebar layout
                  
                ), 
                
                ### End the Data tab panel
                
    )
    
    
  ) 
  ### End the app tabPanelSet
) 
### End the navbarPage
)

VRATserver <- shinyServer(function(input, output, session) {
  
  test <- ContCurrentSideBarPanelServer(id = "ContCurrentSideBarPanel",
                                        reactive(input$appTabs),
                                        Maincount = reactive(input$Maincount))
  })



shinyApp(
  ui = VRATui,
  server = VRATserver
)

标签: rshinymodulereactive

解决方案


结果很容易。我没有正确传递外部参数作为反应性参数。它应该是反应式({...})而不是反应式(...)。一旦更正,模块就会正确响应 appTabs() 并且 if 语句完成且没有错误。当这工作时,文本已正确输入到侧边栏选项卡中。


推荐阅读