swappable: Swappable

View source: R/swappable.R

swappableR Documentation

Swappable

Description

Create swappable elements. swappableItems within swappable can be swapper.

Usage

swappable(inputId, ...)

asSwappable(el)

swappableItem(inputId, ..., class = "")

asSwappableItem(el)

update_swappable(id, order, session = shiny::getDefaultReactiveDomain())

Arguments

...

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 inputIds of draggableItem in desired order.

session

A value reactive domain.

Examples

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)


bigomics/bigdash documentation built on Sept. 14, 2024, 4:38 a.m.