Description Usage Arguments Examples
Use in a Shiny app to sort cards.
1 2 3 4 5 6 7 8 | arrange_cards(
shuffleId,
by,
desc = FALSE,
session = shiny::getDefaultReactiveDomain()
)
randomize_cards(shuffleId, session = shiny::getDefaultReactiveDomain())
|
shuffleId |
The id of the shuffle container. |
by |
Key(s) defined in |
desc |
Logical, set to |
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | if (interactive()) {
library(ggplot2)
library(shiny)
library(shufflecards)
# utility fun
is.even <- function(x) x %% 2 == 0
ui <- fluidPage(
tags$h2("Arrange a Shuffle Grid By Groups"),
fluidRow(
column(
width = 3,
radioButtons(
inputId = "sort",
label = "Sort by:",
choices = c("Ascending order (numeric)",
"Descending order (numeric)",
"Ascending order (character)",
"Descending order (character)",
"Random!")
)
),
column(
width = 9,
shuffle_container(
shuffleId = "gridNum",
card_list = lapply(
X = 1:12,
FUN = function(i) {
shuffle_card(
value_num = i,
value_char = as.character(i), # used to sort
plotOutput(
outputId = paste0("plot", i),
width = "250px",
height = "250px"
)
)
}
)
)
)
)
)
server <- function(input, output, session) {
# Make individual plots ----
lapply(
X = 1:12,
FUN = function(i) {
output[[paste0("plot", i)]] <- renderPlot({
ggplot() + geom_text(aes(1, 1, label = i), size = 50)
})
}
)
# Sorts ----
observe({
if (input$sort == "Ascending order (numeric)") {
arrange_cards("gridNum", "value_num")
} else if (input$sort == "Descending order (numeric)") {
arrange_cards("gridNum", "value_num", desc = TRUE)
} else if (input$sort == "Ascending order (character)") {
arrange_cards("gridNum", "value_char")
} else if (input$sort == "Descending order (character)") {
arrange_cards("gridNum", "value_char", desc = TRUE)
} else{
randomize_cards("gridNum")
}
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.