Description Usage Arguments Examples
Use in a Shiny app to add card(s) to an existing Shuffle grid.
1 2 3 4 5 6 |
shuffleId |
The id of the shuffle container. |
card |
A |
where |
Where to add card : at the beginning or at the end. But careful it can depends on the last arrangement made by the user ! (Check example) |
session |
The |
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 | if (interactive()) {
library(shiny)
library(shufflecards)
library(ggplot2)
ui <- fluidPage(
tags$h2("Add cards to a Shuffle grid"),
actionButton(inputId = "add", label = "Add a new card!"),
actionButton(inputId = "arrange", label = "Arrange cards"),
actionButton(inputId = "arrangedesc", label = "Arrange cards (desc)"),
actionButton(inputId = "random", label = "Randomize cards"),
shuffle_container(
shuffleId = "grid",
shuffle_card(
id = "card1", number = 1,
plotOutput(
outputId = "plot1",
width = "250px",
height = "250px"
)
)
)
)
server <- function(input, output, session) {
# First plot
output$plot1 <- renderPlot({
ggplot() + geom_text(aes(1, 1, label = 1), size = 50)
})
# counter of cards
counter <- reactiveVal(1)
# Update counter when button is clickeck
observeEvent(input$add, {
newValue <- counter() + 1
counter(newValue)
}, ignoreInit = TRUE)
# When counter change add a card
observeEvent(counter(), {
num <- counter()
add_card(
session = session,
shuffleId = "grid",
card = shuffle_card(
id = paste0("card", num), number = num,
plotOutput(outputId = paste("plot", num), width = "250px", height = "250px")
)
)
output[[paste("plot", num)]] <- renderPlot({
ggplot() + geom_text(aes(1, 1, label = num), size = 50)
})
}, ignoreInit = TRUE)
# Arrange ----
observeEvent(input$arrange, {
arrange_cards("grid", "number")
})
observeEvent(input$arrangedesc, {
arrange_cards("grid", "number", desc = TRUE)
})
observeEvent(input$random, {
randomize_cards("grid")
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.