update_card: Update meta-data of a card

Description Usage Arguments Examples

View source: R/update.R

Description

Use in a Shiny app to update data associated to a card.

Usage

1
2
3
4
5
6
7
update_card(
  shuffleId,
  cardId,
  ...,
  title = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

shuffleId

The id of the shuffle container.

cardId

The id of the card to update

...

Attributes to update or set.

title

New title for the card.

session

The session object passed to function given to shinyServer.

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
79
80
81
82
if (interactive()) {
  library(shiny)
  library(shufflecards)

  ui <- fluidPage(
    tags$h2("Update cards's meta-data"),

    fluidRow(
      column(
        width = 3,
        sliderInput("val1", "Value card 1", 1, 10, 1),
        sliderInput("val2", "Value card 2", 1, 10, 2),
        sliderInput("val3", "Value card 3", 1, 10, 3),
        sliderInput("val4", "Value card 4", 1, 10, 4),
        actionButton("arrange", "Arrange cards with new values")
      ),
      column(
        width = 9,
        shuffle_container(
          shuffleId = "grid",
          shuffle_card(
            id = "card1",
            myvalue = 1,
            tags$div("My first card", style = "text-align: center; line-height: 200px"),
            style = "border: 2px solid red; border-radius: 5px;",
            width = "300px", # better with fixed width/height
            height = "200px"
          ),
          shuffle_card(
            id = "card2",
            myvalue = 2,
            tags$div("Second one", style = "text-align: center; line-height: 200px"),
            style = "border: 2px solid red; border-radius: 5px;",
            width = "300px", # better with fixed width/height
            height = "200px"
          ),
          shuffle_card(
            id = "card3",
            myvalue = 3,
            tags$div("Third one", style = "text-align: center; line-height: 200px"),
            style = "border: 2px solid red; border-radius: 5px;",
            width = "300px", # better with fixed width/height
            height = "200px"
          ),
          shuffle_card(
            id = "card4",
            myvalue = 4,
            tags$div("Fourth one", style = "text-align: center; line-height: 200px"),
            style = "border: 2px solid red; border-radius: 5px;",
            width = "300px", # better with fixed width/height
            height = "200px"
          )
        )
      )
    )

  )

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

    # Update cards ----
    observeEvent(input$val1, {
      update_card("grid", "card1", myvalue = input$val1)
    }, ignoreInit = TRUE)
    observeEvent(input$val2, {
      update_card("grid", "card2", myvalue = input$val2)
    }, ignoreInit = TRUE)
    observeEvent(input$val3, {
      update_card("grid", "card3", myvalue = input$val3)
    }, ignoreInit = TRUE)
    observeEvent(input$val4, {
      update_card("grid", "card4", myvalue = input$val4)
    }, ignoreInit = TRUE)

    # Arrange ----
    observeEvent(input$arrange, {
      arrange_cards("grid", "myvalue", numeric = TRUE)
    })
  }

  shinyApp(ui, server)
}

dreamRs/shufflecards documentation built on Dec. 4, 2019, 4:44 a.m.