【问题标题】:How to modularize directory selector for the golem framework?如何为 golem 框架模块化目录选择器?
【发布时间】:2020-10-02 00:43:12
【问题描述】:

我一直在开发一个闪亮的应用程序,我想将它集成到 golem 框架中。我使用了来自shinyFiles package 的目录选择器,但是在尝试对其进行模块化时遇到了一些问题(闪亮的应用程序不再显示我的目录)。不得不说我是闪亮应用程序开发的初学者。任何建议都非常感谢:

#' datadir UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_datadir_ui <- function(id){
   ns <- NS(id)
   tagList(
     shinyDirButton("datadir", "Raw data directory",
                    "Please select the folder containing the raw accelerometer data")
   )
}

#' datadir Server Function
#'
#' @noRd
mod_datadir_server <- function(input, output, session){
   ns <- session$ns
   volumes <- c(Home = fs::path_home(), "R Installation" = R.home(),
                getVolumes()())

   # DATADIR
   shinyDirChoose(input, "datadir", roots = volumes, session = session,
                  restrictions = system.file(package = "base"))
}

## To be copied in the UI
# mod_datadir_ui("datadir_ui_1")

## To be copied in the server
# callModule(mod_datadir_server, "datadir_ui_1")

【问题讨论】:

    标签: r session shiny volumes golem


    【解决方案1】:

    为id添加ns

    #'
    #' @description A shiny Module.
    #'
    #' @param id,input,output,session Internal parameters for {shiny}.
    #'
    #' @noRd
    #'
    #' @importFrom shiny NS tagList
    mod_datadir_ui <- function(id){
      ns <- NS(id)
      tagList(
        shinyDirButton(ns("datadir"), "Raw data directory",
                       "Please select the folder containing the raw accelerometer data")
      )
    }
    
    #' datadir Server Function
    #'
    #' @noRd
    mod_datadir_server <- function(input, output, session){
      ns <- session$ns
      volumes <- c(Home = fs::path_home(), "R Installation" = R.home(),
                   getVolumes()())
    
      # DATADIR
      shinyDirChoose(input, "datadir", roots = volumes, session = session,
                     restrictions = system.file(package = "base"))
    }
    
    ## To be copied in the UI
    # mod_datadir_ui("datadir_ui_1")
    
    ## To be copied in the server
    
    
    library(shiny)
    library(shinyFiles)
    
    ui <- fluidPage(
      mod_datadir_ui('jean')
    )
    
    server <- function(input, output, session) {
      callModule(mod_datadir_server, "jean")
    }
    
    shinyApp(ui, server)
    

    看起来它现在可以工作了。

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 1970-01-01
      • 2013-02-19
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多