0

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

#' 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")
4

1 回答 1

2

为 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)

看起来它现在正在工作。

于 2020-06-12T08:59:35.583 回答