为什么我在加载数据面板下看不到我的数据?

问题描述 投票:0回答:1

我的导航栏中有两个选项卡(我试图保持简单,我有更多选项卡,但并不重要)。现在,我可以按照我想要的方式获取信息选项卡。但是,当我上传加载数据的模块时,我无法在“加载数据”选项卡下获取它,而是在第一个选项卡 - Info 下获取它。

这是代码片段(尽管我可以根据请求授予对存储库的访问权限 - https://github.com/gabrielburcea/grwtgolem),它是 golem 闪亮框架,并且希望保持这种方式。

首先,我定义

app_ui

app_ui <- function(request) {
  tagList(# Leave this function for adding external resources
    golem_add_external_resources(),
    shinyjs::useShinyjs(),
    
    # Your application UI logic
    shinyUI(
      shiny::navbarPage(title = div(tags$a(img(src = "www/RGB.png", height = "50px"), "Growth Rate Explorer"),
                                    id = "navBar",
                                    theme = "www/style.css",
                                    # collapsible = TRUE,
                                    # inverse = TRUE,
                                    style = "position: relative; top: -30px; margin-left: 10px; margin-top: 5px;"),
                        header = tags$head(includeCSS("www/style.css")),# sourcing css style sheet
                        # make navigation bar collapse on smaller screens
                        windowTitle = "Growt",
                        collapsible = TRUE,
                        
                        shiny::tabPanel("Info", icon = icon("fa-light fa-info"), mod_info_app_ui("info_app_1")),
                        
                        shiny::tabPanel("Load Data", icon = icon("fa-light fa-database"), mod_load_app_ui("load_app_1"))
                        
      )
    )
  )
}

然后,我将

server_app
定义为:

#' app_server
#'
#' @param input,output,session Internal parameters for {shiny}.
#'     DO NOT REMOVE.
#' @import shiny
#' @noRd
app_server <- function(input, output, session){

  mod_info_app_server("info_app_1")
  mod_load_app_server("load_app_1")
 
}

重申一下,我在信息选项卡下找到了我的加载应用程序。为什么会出现这种情况?

过去两天我尝试了不同的配置,但没有任何帮助。

我尝试使用

shiny::callModule(mod_load_server, mod_load_ui_1)
重新定义 app_server,但它没有任何作用。

供您参考:

mod_info_app
mod_load_app

第一个是 mod_info_app,它包含 html 脚本(我不会提供,这些脚本太大了),但是这个模块定义了信息选项卡的 ui 和服务器,就像 golem 所要求的那样:

#'mod_info_app_ui UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_info_app_ui <- function(id){
  ns <- NS(id)
  tagList(
    tagList(shiny::tabPanel(title = "Info",
                            tags$div(
                              class = "main",
                              shiny::fluidPage(
                                htmltools::htmlTemplate("www/welcome_to_growth_rate_explorer.html"),
                                htmltools::htmlTemplate("www/info_tabs_list.html")
                              )
                            )))


  )
}

#' mod_info_app_server Server Functions
#'
#' @noRd
mod_info_app_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns

    # Color coding
    colorCoding <- reactive({

      tagList(
        tags$b("Legend"),
        tags$p(drawBullet(color = paste(myColors[1], "; border: 1px solid black")), "Adjusted p Value > 0.05"),
        tags$p(drawBullet(color = myColors[2]), "0.01 < Adjusted p Value", HTML("&le;"), "0.05"),
        tags$p(drawBullet(color = myColors[3]), "0.001 < Adjusted p Value", HTML("&le;"), "0.01"),
        tags$p(drawBullet(color = myColors[4]), "0.0001 < Adjusted p Value", HTML("&le;"), "0.001"),
        tags$p(drawBullet(color = myColors[5]), "Adjusted p Value", HTML("&le;"), "0.0001")

      )

    })

    output$info_colorCoding <- renderUI(colorCoding()) 

   etc, etc, 





  })
}

然后是mod_load_app,定义了ui和服务器,有点长,仅供自己制作:

#' mod_load_app_ui UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_load_app_ui <- function(id) {
  ns <- NS(id)
  tagList(shiny::tabPanel(
    title = "Load Data",

    tags$br(),

    shiny::sidebarLayout(
      shiny::sidebarPanel(
        hidden(
          actionButton(
            inputId = "load_loadNewButton",
            icon = icon("arrow-alt-circle-up"),
            label = "Upload new data"
          )
        ),
        # Load data
        div(
          id = "load_inputDataSpecifics",
          fileInput(
            inputId = "load_file",
            label = "Data File(s)",
            accept = c(".csv", ".xlsx"),
            multiple = TRUE
          ),
          uiOutput("load_selectColumnNamesUI"),
          uiOutput("load_dayOffsetInput"),
          uiOutput("load_loadDataButtonUI")

        ),
        uiOutput("load_warnings"), etc, etc, etc, etc

  
          )
        )
      )
    )
  ))

}

#' mod_load_app_server Server Functions
#'
#' @noRd
mod_load_app_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns


    observe({
      req(results$load_dataType())

      if(length(input$load_loadDataButton) ==1){
        toggleElement(id = "load_MBPlotFacet", condition = results$load_dataType() ==2)
      }

      toggleElement(id = "load_excludeIdSelect", condition = input$load_outlierType %in% c(1,3))
      toggleElement(id = "load_excludeButton", condition = isTruthy(input$load_excludeReason))
      toggleElement(id = "load_excludeDaySelect", condition = input$load_outlierType %in% c(2,3))

    })

    observe({
      req(results$load_dataVolume())
      updateSelectInput(session,
                        inputId= "load_excludeDaySelect",
                        choices = sort(unique(results$load_dataVolume()$day)))

      sortedIds <- list()
      for(treatment in levels(results$load_dataVolume()$treatment)){
        ids <- unique(results$load_dataVolume()$animal_id[results$load_dataVolume()$treatment == treatment])
        sortedIds[[treatment]] <- ids
      }

      updateSelectInput(session, inputId= "load_excludeIdSelect", choices = sortedIds)
    })

    output$load_selectColumnNamesUI <- renderUI({
      req(results$load_dataInputFile0())

      myColumns <- matchColumns(results$load_dataInputFile0())
      names <- names(myColumns)
      inputIds <- paste0("load_columnName_", names)

      tagList(
        textInput("load_dayOffset",
                  label = "Specify how day is defined",
                  value = "Post-implant"),
        helpText("Please check whether the program has detected the right columns"),
        lapply(1:length(myColumns), function(i)
          selectizeInput(inputId = inputIds[i],
                         label = names[i],
                         choices = myColumns[[i]]$options,
                         selected = myColumns[[i]]$guess))
      )
    }) etc, etc, etc.. 



}

## To be copied in the UI
# mod_load_app_ui("load_app_1")

## To be copied in the server
# mod_load_app_server("load_app_1")

......添加更多----------

如果你看的话,你可以看到正文页面出现在两个选项卡下,无论我选择哪个

第二张图

第三张图片包含与信息选项卡混合的负载数据信息:

shiny shinydashboard reactive shinyapps golem
1个回答
0
投票

简单的答案是,在 info_ui 脚本中我有一个 html,在 html 的末尾我想添加另一个

</div>

© www.soinside.com 2019 - 2024. All rights reserved.