diff --git a/R/tm_file_viewer.R b/R/tm_file_viewer.R index 7a3ae61ff..8be167330 100644 --- a/R/tm_file_viewer.R +++ b/R/tm_file_viewer.R @@ -1,34 +1,32 @@ -#' File Viewer `teal` Module +#' File viewer module #' #' The file viewer module provides a tool to view static files. -#' Supported formats include text formats, \code{PDF}, \code{PNG}, \code{APNG}, -#' \code{JPEG}, \code{SVG}, \code{WEBP}, \code{GIF} and \code{BMP}. +#' Supported formats include text formats, `PDF`, `PNG` `APNG`, +#' `JPEG` `SVG`, `WEBP`, `GIF` and `BMP`. #' #' @inheritParams teal::module #' @inheritParams shared_params -#' @param input_path optional, (`list`) of the input paths to either: specific files of accepted formats, -#' a directory or a URL. The paths can be specified as absolute paths or relative to the running -#' directory of the application. Will default to current working directory if not supplied. +#' @param input_path (`list`) of the input paths, optional. Each element can be: #' -#' @export +#' 1. Specific path to files of accepted formats +#' 2. A directory or a URL #' -#' @examples -#' data <- teal_data() -#' data <- within(data, { -#' data <- data.frame(1) -#' }) -#' datanames(data) <- c("data") +#' The paths can be specified as absolute paths or relative to the running +#' directory of the application. +#' Default to the current working directory if not supplied. +#' +#' @inherit shared_params return #' -#' app <- teal::init( -#' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_file_viewer( +#' @examples +#' app <- init( +#' data = teal_data(data = 1), # Mock dataset to initialize the app without error +#' modules = modules( +#' tm_file_viewer( #' input_path = list( #' folder = system.file("sample_files", package = "teal.modules.general"), #' png = system.file("sample_files/sample_file.png", package = "teal.modules.general"), #' txt = system.file("sample_files/sample_file.txt", package = "teal.modules.general"), -#' url = -#' "https://www.fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf" +#' url = "https://fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf" #' ) #' ) #' ) @@ -36,6 +34,7 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' @export #' tm_file_viewer <- function(label = "File Viewer Module", input_path = list("Current Working Directory" = ".")) { @@ -90,6 +89,7 @@ tm_file_viewer <- function(label = "File Viewer Module", ) } +# UI function for the file viewer module ui_viewer <- function(id, ...) { args <- list(...) ns <- NS(id) @@ -116,6 +116,7 @@ ui_viewer <- function(id, ...) { ) } +# Server function for the file viewer module srv_viewer <- function(id, input_path) { moduleServer(id, function(input, output, session) { temp_dir <- tempfile() diff --git a/man/tm_file_viewer.Rd b/man/tm_file_viewer.Rd index ace7d9e6d..79a3476f3 100644 --- a/man/tm_file_viewer.Rd +++ b/man/tm_file_viewer.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/tm_file_viewer.R \name{tm_file_viewer} \alias{tm_file_viewer} -\title{File Viewer \code{teal} Module} +\title{File viewer module} \usage{ tm_file_viewer( label = "File Viewer Module", @@ -13,32 +13,34 @@ tm_file_viewer( \item{label}{(\code{character(1)}) Label shown in the navigation item for the module or module group. For \code{modules()} defaults to \code{"root"}. See \code{Details}.} -\item{input_path}{optional, (\code{list}) of the input paths to either: specific files of accepted formats, -a directory or a URL. The paths can be specified as absolute paths or relative to the running -directory of the application. Will default to current working directory if not supplied.} +\item{input_path}{(\code{list}) of the input paths, optional. Each element can be: +\enumerate{ +\item Specific path to files of accepted formats +\item A directory or a URL +} + +The paths can be specified as absolute paths or relative to the running +directory of the application. +Default to the current working directory if not supplied.} +} +\value{ +Object of class \code{teal_module} to be used in \code{teal} applications. } \description{ The file viewer module provides a tool to view static files. -Supported formats include text formats, \code{PDF}, \code{PNG}, \code{APNG}, -\code{JPEG}, \code{SVG}, \code{WEBP}, \code{GIF} and \code{BMP}. +Supported formats include text formats, \code{PDF}, \code{PNG} \code{APNG}, +\code{JPEG} \code{SVG}, \code{WEBP}, \code{GIF} and \code{BMP}. } \examples{ -data <- teal_data() -data <- within(data, { - data <- data.frame(1) -}) -datanames(data) <- c("data") - -app <- teal::init( - data = data, - modules = teal::modules( - teal.modules.general::tm_file_viewer( +app <- init( + data = teal_data(data = 1), # Mock dataset to initialize the app without error + modules = modules( + tm_file_viewer( input_path = list( folder = system.file("sample_files", package = "teal.modules.general"), png = system.file("sample_files/sample_file.png", package = "teal.modules.general"), txt = system.file("sample_files/sample_file.txt", package = "teal.modules.general"), - url = - "https://www.fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf" + url = "https://fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf" ) ) ) @@ -46,5 +48,4 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } - }