From bf2c47cd83cb8fc2cd242ce539078486a6bb8eba Mon Sep 17 00:00:00 2001 From: pvictor Date: Tue, 23 Nov 2021 18:24:01 +0100 Subject: [PATCH] updated examples --- R/import-globalenv.R | 6 ++- examples/from-globalenv.R | 94 +++++++++++++++++++-------------------- man/get_data_packages.Rd | 6 ++- man/import-globalenv.Rd | 86 +++++++++++++++++------------------ 4 files changed, 100 insertions(+), 92 deletions(-) diff --git a/R/import-globalenv.R b/R/import-globalenv.R index 4f9ee54..fa17332 100644 --- a/R/import-globalenv.R +++ b/R/import-globalenv.R @@ -260,7 +260,11 @@ import_globalenv_server <- function(id, #' @importFrom utils data #' #' @examples -#' get_data_packages() +#' if (interactive()) { +#' +#' get_data_packages() +#' +#' } get_data_packages <- function() { suppressWarnings({ pkgs <- data(package = .packages(all.available = TRUE)) diff --git a/examples/from-globalenv.R b/examples/from-globalenv.R index 7675427..d756fe4 100644 --- a/examples/from-globalenv.R +++ b/examples/from-globalenv.R @@ -1,56 +1,56 @@ +if (interactive()) { + library(shiny) + library(datamods) -library(shiny) -library(datamods) - -# Create some data.frames - -my_df <- data.frame( - variable1 = sample(letters, 20, TRUE), - variable2 = sample(1:100, 20, TRUE) -) - -results_analysis <- data.frame( - id = sample(letters, 20, TRUE), - measure = sample(1:100, 20, TRUE), - response = sample(1:100, 20, TRUE) -) - - -# Application - -ui <- fluidPage( - fluidRow( - column( - width = 4, - import_globalenv_ui("myid") - ), - column( - width = 8, - tags$b("Import status:"), - verbatimTextOutput(outputId = "status"), - tags$b("Name:"), - verbatimTextOutput(outputId = "name"), - tags$b("Data:"), - verbatimTextOutput(outputId = "data") + # Create some data.frames + + my_df <- data.frame( + variable1 = sample(letters, 20, TRUE), + variable2 = sample(1:100, 20, TRUE) + ) + + results_analysis <- data.frame( + id = sample(letters, 20, TRUE), + measure = sample(1:100, 20, TRUE), + response = sample(1:100, 20, TRUE) + ) + + + # Application + + ui <- fluidPage( + fluidRow( + column( + width = 4, + import_globalenv_ui("myid") + ), + column( + width = 8, + tags$b("Import status:"), + verbatimTextOutput(outputId = "status"), + tags$b("Name:"), + verbatimTextOutput(outputId = "name"), + tags$b("Data:"), + verbatimTextOutput(outputId = "data") + ) ) ) -) -server <- function(input, output, session) { + server <- function(input, output, session) { - imported <- import_globalenv_server("myid") + imported <- import_globalenv_server("myid") - output$status <- renderPrint({ - imported$status() - }) - output$name <- renderPrint({ - imported$name() - }) - output$data <- renderPrint({ - imported$data() - }) + output$status <- renderPrint({ + imported$status() + }) + output$name <- renderPrint({ + imported$name() + }) + output$data <- renderPrint({ + imported$data() + }) -} + } -if (interactive()) shinyApp(ui, server) +} diff --git a/man/get_data_packages.Rd b/man/get_data_packages.Rd index 4fcd5df..0b48dee 100644 --- a/man/get_data_packages.Rd +++ b/man/get_data_packages.Rd @@ -13,5 +13,9 @@ a character vector of packages names Get packages containing datasets } \examples{ -get_data_packages() +if (interactive()) { + + get_data_packages() + +} } diff --git a/man/import-globalenv.Rd b/man/import-globalenv.Rd index ae53253..cab6dcf 100644 --- a/man/import-globalenv.Rd +++ b/man/import-globalenv.Rd @@ -56,60 +56,60 @@ use \code{NULL} for no title or a \code{shiny.tag} for a custom one.} Let the user select a dataset from its own environment or from a package's environment. } \examples{ +if (interactive()) { + library(shiny) + library(datamods) -library(shiny) -library(datamods) + # Create some data.frames -# Create some data.frames - -my_df <- data.frame( - variable1 = sample(letters, 20, TRUE), - variable2 = sample(1:100, 20, TRUE) -) + my_df <- data.frame( + variable1 = sample(letters, 20, TRUE), + variable2 = sample(1:100, 20, TRUE) + ) -results_analysis <- data.frame( - id = sample(letters, 20, TRUE), - measure = sample(1:100, 20, TRUE), - response = sample(1:100, 20, TRUE) -) + results_analysis <- data.frame( + id = sample(letters, 20, TRUE), + measure = sample(1:100, 20, TRUE), + response = sample(1:100, 20, TRUE) + ) -# Application - -ui <- fluidPage( - fluidRow( - column( - width = 4, - import_globalenv_ui("myid") - ), - column( - width = 8, - tags$b("Import status:"), - verbatimTextOutput(outputId = "status"), - tags$b("Name:"), - verbatimTextOutput(outputId = "name"), - tags$b("Data:"), - verbatimTextOutput(outputId = "data") + # Application + + ui <- fluidPage( + fluidRow( + column( + width = 4, + import_globalenv_ui("myid") + ), + column( + width = 8, + tags$b("Import status:"), + verbatimTextOutput(outputId = "status"), + tags$b("Name:"), + verbatimTextOutput(outputId = "name"), + tags$b("Data:"), + verbatimTextOutput(outputId = "data") + ) ) ) -) -server <- function(input, output, session) { + server <- function(input, output, session) { - imported <- import_globalenv_server("myid") + imported <- import_globalenv_server("myid") - output$status <- renderPrint({ - imported$status() - }) - output$name <- renderPrint({ - imported$name() - }) - output$data <- renderPrint({ - imported$data() - }) + output$status <- renderPrint({ + imported$status() + }) + output$name <- renderPrint({ + imported$name() + }) + output$data <- renderPrint({ + imported$data() + }) -} + } -if (interactive()) shinyApp(ui, server) } +}