Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-release tm_file_viewer document update #665

Merged
merged 8 commits into from
Feb 26, 2024
39 changes: 20 additions & 19 deletions R/tm_file_viewer.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
#' 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"
#' )
#' )
#' )
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#' @export
#'
tm_file_viewer <- function(label = "File Viewer Module",
input_path = list("Current Working Directory" = ".")) {
Expand Down Expand Up @@ -90,6 +89,7 @@ tm_file_viewer <- function(label = "File Viewer Module",
)
}

# UI function for the file viewer module
m7pr marked this conversation as resolved.
Show resolved Hide resolved
ui_viewer <- function(id, ...) {
args <- list(...)
ns <- NS(id)
Expand All @@ -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()
Expand Down
39 changes: 20 additions & 19 deletions man/tm_file_viewer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.