importData: shiny UI to import data

Description Usage Arguments Examples

Description

A module to enable data importation in shiny applications, by clicking on a button or link action, man can open a modal window to let import dataset in shiny application. The module support CSV, Excel and SAS datasets.

Usage

1
2
3
4
5
6
importDataUI(id)

importDataServer(input, output, session,
  forbidden_labels = reactive(NULL), default_tofact = FALSE,
  ui_element = "actionLink", ui_label = "Import",
  ui_icon = icon("upload"), labelize = FALSE)

Arguments

id

namespace identifier for the module

input, output, session

mandatory arguments for modules to be valid. These should not to be defined as they will be handled by shiny.

forbidden_labels

Optional, reactive value, forbidden labels as a character vector

default_tofact

If default convert characters to factors. Default FALSE.

ui_element

UI element to show, either "actionButton", or "actionLink". Default "actionLink".

ui_label

Label of ui element. Default to "import".

ui_icon

Icon of ui element. Default to icon("upload").

labelize

if TRUE a label is required to import the data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
library(shinytools)
library(DT)
library(shiny)

if (interactive()) {
  options(device.ask.default = FALSE)

  ui <- fluidPage(
    load_tingle(),
    importDataUI(id = "id1"),
    uiOutput("ui_SI_labels"),
    DT::dataTableOutput(outputId = "id2")
  )

  server <- function(input, output) {

    dataset <- callModule(
      module = importDataServer,
      id = "id1", ui_element = "actionButton",
      labelize = FALSE)

    output$id2 <- DT::renderDataTable({
      req(dataset$trigger > 0)
      dataset$object
    })
  }

  print(shinyApp(ui, server))
}



if (interactive()) {
  options(device.ask.default = FALSE)

  ui <- fluidPage(
    titlePanel("Import and visualize dataset"),
    sidebarLayout(
      sidebarPanel(
        load_tingle(),
        importDataUI(id = "id1"),
        uiOutput("ui_SI_labels")
      ),
      mainPanel(
        DT::dataTableOutput(outputId = "id2")
      )
    )
  )

  server <- function(input, output) {
    all_datasets <- reactiveValues()

    datasets <- callModule(
      module = importDataServer,
      id = "id1", ui_element = "actionButton",
      labelize = TRUE,
      forbidden_labels = reactive(names(reactiveValuesToList(all_datasets))))

    observeEvent(datasets$trigger, {
      req(datasets$trigger > 0)
      all_datasets[[datasets$name]] <- datasets$object
    })

    output$ui_SI_labels <- renderUI({
      x <- reactiveValuesToList(all_datasets)
      if (length(x) > 0) {
        selectInput("SI_labels", label = "Choose dataset", choices = names(x))
      }
    })

    output$id2 <- DT::renderDataTable({
      req(input$SI_labels)
      all_datasets[[input$SI_labels]]
    })
  }

  print(shinyApp(ui, server))
}

ardata-fr/shinytools documentation built on Nov. 15, 2019, 7:53 p.m.