import-globalenv {datamods}R Documentation

Import data from an Environment

Description

Let the user select a dataset from its own environment or from a package's environment.

Usage

import_globalenv_ui(
  id,
  globalenv = TRUE,
  packages = get_data_packages(),
  title = TRUE
)

import_globalenv_server(
  id,
  btn_show_data = TRUE,
  show_data_in = c("popup", "modal"),
  trigger_return = c("button", "change"),
  return_class = c("data.frame", "data.table", "tbl_df", "raw"),
  reset = reactive(NULL)
)

Arguments

id

Module's ID.

globalenv

Search for data in Global environment.

packages

Name of packages in which to search data.

title

Module's title, if TRUE use the default title, use NULL for no title or a shiny.tag for a custom one.

btn_show_data

Display or not a button to display data in a modal window if import is successful.

show_data_in

Where to display data: in a "popup" or in a "modal" window.

trigger_return

When to update selected data: "button" (when user click on button) or "change" (each time user select a dataset in the list).

return_class

Class of returned data: data.frame, data.table, tbl_df (tibble) or raw.

reset

A reactive function that when triggered resets the data.

Value

Examples

if (interactive()) {
  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")
      )
    )
  )

  server <- function(input, output, session) {

    imported <- import_globalenv_server("myid")

    output$status <- renderPrint({
      imported$status()
    })
    output$name <- renderPrint({
      imported$name()
    })
    output$data <- renderPrint({
      imported$data()
    })

  }

  shinyApp(ui, server)
}

[Package datamods version 1.5.1 Index]