r - 如何为 golem 框架模块化目录选择器?
问题描述
我一直在开发一个闪亮的应用程序,我想将它集成到 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")
解决方案
为 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)
看起来它现在正在工作。
推荐阅读
- javascript - 导出数据表中流水线数据的问题
- ios - 我是否需要 iPhone 来构建 Xcode 并上传到 Appstore?
- typescript - 从库默认导出创建类型
- ios - Swift - insertSubview 用法
- javascript - 如何检查对象数组的长度这里对象内部有数组?
- abap - 正确的消息服务器端口 (msserv)?
- javascript - Lodash groupby 多个条件
- java - PostgreSQL 使用 JPA 和 Hibernate 抛出“列类型为 jsonb 但表达式类型为 bytea”
- django - SurveyMonkey:如何按 custom_variables 过滤响应
- c# - Google API vs Google Play vs Intel x86 vs Android TV vs Wear OS Intel x86 系统映像差异