Learn R Programming

r2resize (version 2.0)

windowCard: Resizable, Moveable, and Expandable Window Card

Description

Creates an easily expandable, resizable, and moveable window-like container for content, mimicking a desktop window within your Shiny application or HTML output.

Usage

windowCard(
  ...,
  title = "Sample title",
  width = "50%",
  bg.color = NULL,
  border.color = NULL,
  header.text.color = NULL,
  body.text.color = NULL
)

Value

A `shiny::div` element representing the moveable, resizable, and expandable window card.

Arguments

...

The content to be placed inside the window card. Can be any `shiny::tagList` or HTML content.

title

The title displayed in the header of the window card.

width

The initial width of the window card (e.g., "50%", "600px").

bg.color

The background color of the content area within the window card. Can be a named R color or a hexadecimal color code.

border.color

The border color of the entire window card. Can be a named R color or a hexadecimal color code.

header.text.color

The text color of the title in the header.

body.text.color

The text color of the content within the card's body.

Examples for r2resize

More examples and demo pages are located at this link - https://rpkg.net/package/r2resize.

Details

The `windowCard` function is a versatile UI component that allows for highly interactive content display. Users can drag the window around the page, resize it from its edges, and expand/collapse its content. This is particularly useful for pop-up information, draggable dashboards, or interactive panels in complex Shiny applications. The window initially appears centered on the screen.

See Also

splitCard, splitCard2, sizeableCard

Other Container Functions: empahsisCard(), sizeableCard(), splitCard(), splitCard2()

Examples

Run this code
if (interactive()) {
  library(shiny)
  # Simple window card with default attributes
  shinyApp(
    ui = fluidPage(
      h2("Interactive Window Card"),
      windowCard(
        shiny::h3("Welcome!"),
        shiny::p("This is a draggable and resizable window."),
        shiny::actionButton("closeBtn", "Close Window")
      )
    ),
    server = function(input, output) {
      observeEvent(input$closeBtn, {
        # Example: How you might handle closing (requires custom JS for actual close)
        showNotification("Window close requested (functionality not built-in)")
      })
    }
  )

  # Custom styled window card with a plot
  shinyApp(
    ui = fluidPage(
      h2("Styled Window Card with Plot"),
      windowCard(
        title = "Dynamic Plot Window",
        width = "600px",
        bg.color = "#E8F5E9",
        border.color = "#4CAF50",
        header.text.color = "white",
        body.text.color = "#333333",
        shiny::plotOutput("myPlot")
      )
    ),
    server = function(input, output) {
      output$myPlot <- shiny::renderPlot({
        hist(rnorm(100), col = "skyblue", border = "white", main = "Random Normal Data")
      })
    }
  )
}

Run the code above in your browser using DataLab