swappable | R Documentation |
Create swappable elements.
swappableItem
s within swappable
can be swapper.
swappable(inputId, ...)
asSwappable(el)
swappableItem(inputId, ..., class = "")
asSwappableItem(el)
update_swappable(id, order, session = shiny::getDefaultReactiveDomain())
... |
Content, HTML tags. |
el |
Element to apply type to. |
class |
Any additional class to pass to parent div. |
id , inputId |
Id of input. |
order |
List of |
session |
A value reactive domain. |
library(shiny)
ui <- bigPage(
sidebar = sidebar(
"Menu",
sidebarItem(
"Home",
"home"
)
),
bigTabs(
bigTabItem(
"home",
div(
class = "p-4",
h1("Hello"),
actionButton("reorder", "randomise order"),
swappable(
inputId = "swap",
fluidRow(
swappableItem(
inputId = "s1",
class = "col-6",
div(
class = "card",
div(
class = "card-body",
plotOutput("plot1")
)
)
),
swappableItem(
inputId = "s2",
class = "col-3",
div(
class = "card",
div(
class = "card-body",
h3("Something")
)
)
),
swappableItem(
inputId = "s3",
class = "col-3",
div(
class = "card",
div(
class = "card-body",
h5("Something else")
)
)
)
)
)
)
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlot({
plot(cars)
})
observeEvent(input$swap, {
print(input$swap)
})
observeEvent(input$reorder, {
order <- sample(
c(
"s1",
"s2",
"s3"
)
)
update_swappable("swap", order)
})
}
if(interactive())
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.