coerce-module: Coerce data.frame's columns module

Description Usage Arguments Value Examples

Description

Coerce data.frame's columns module

Usage

1
2
3
coerceUI(id)

coerceServer(input, output, session, data, reactiveValuesSlot = "data")

Arguments

id

Module's id

input

standard shiny input.

output

standard shiny output.

session

standard shiny session.

data

A data.frame or a reactive function returning a data.frame or a reactivevalues with a slot containing a data.frame (use reactiveValuesSlot to identify that slot)

reactiveValuesSlot

If data is a reactivevalues, specify the name of the slot containing data.

Value

a reactiveValues with two slots: data original data.frame with modified columns, and names column's names with call to coerce method.

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
if (interactive()) {
  library(esquisse)
  library(shiny)
  
  foo <- data.frame(
    num_as_char = as.character(1:10),
    char = sample(letters[1:3], 10, TRUE),
    fact = factor(sample(LETTERS[1:3], 10, TRUE)),
    date_as_char =  as.character(
      Sys.Date() + sample(seq(-10, 10), 10, TRUE)
    ),
    date_as_num = as.numeric(
      Sys.Date() + sample(seq(-10, 10), 10, TRUE)
    ),
    datetime = Sys.time() + sample(seq(-10, 10) * 1e4, 10, TRUE), 
    stringsAsFactors = FALSE
  )
  
  ui <- fluidPage(
    tags$h2("Coerce module"),
    fluidRow(
      column(
        width = 4,
        coerceUI(id = "exemple", data = foo)
      ),
      column(
        width = 8,
        verbatimTextOutput(outputId = "print_result"),
        verbatimTextOutput(outputId = "print_names")
      )
    )
  )
  
  server <- function(input, output, session) {
    
    result <- callModule(module = coerceServer, id = "exemple", data = foo)
    
    output$print_result <- renderPrint({
      str(result$data)
    })
    output$print_names <- renderPrint({
      result$names
    })
  }
  
  shinyApp(ui, server)
}

dreamRs/esquisse documentation built on Nov. 25, 2018, 7:26 p.m.