Interactive Data

Need to write myself

Dashboards are powerful tools for presenting data and insights in a cohesive, interactive way. The flexdashboard package in R makes it easy to create professional dashboards that combine plots, tables, and text in a flexible layout. This topic introduces you to setting up flexdashboard, integrating different elements, and embedding Shiny apps for added interactivity.


1. Setting Up a Flexible Dashboard Layout

flexdashboard enables you to create dashboards in R Markdown format. Dashboards consist of rows, columns, and panes, allowing you to arrange your content dynamically. Let’s start by creating a basic layout.

Step 1: Install flexdashboard

r
Copy code
install.packages("flexdashboard")

Step 2: Create a New flexdashboard Project

  • Open RStudio.
  • Navigate to File > New File > R Markdown > From Template > Flex Dashboard.
  • Save the file with an .Rmd extension.

Step 3: Structure of a Basic flexdashboard

The header of a flexdashboard defines its layout. For example:

---
title: "My Dashboard"
output:
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---
  • orientation: Specifies whether the dashboard is organized into rows or columns.
  • vertical_layout: Determines how content scales. Use fill for content to stretch to fill the screen or scroll for scrollable panes.

Basic Example

Basic Shiny Integration

### Interactive Plot

```r
library(shiny)

sliderInput("bins", "Number of bins:", 1, 50, 30)

output$plot <- renderPlot({
  hist(rnorm(500), breaks = input$bins, col = 'skyblue', border = 'white')
})

Basic Shiny Integration

Interactive Plot

library(shiny)

sliderInput("bins", "Number of bins:", 1, 50, 30)

output$plot <- renderPlot({
  hist(rnorm(500), breaks = input$bins, col = 'skyblue', border = 'white')
})

Interactive Filter Example

Create a filterable data table using DT and Shiny:

Interactive Table

library(DT)

output$table <- renderDT({
  datatable(mtcars, filter = "top")
})
With Shiny, users can control the inputs and see the results update instantly, making your dashboard highly interactive.

---

### Summary

In this topic, you’ve learned how to:
- Set up a flexible layout using `flexdashboard` by defining rows, columns, and panes in R Markdown.
- Integrate various elements like **plots**, **tables**, and **text** to create a dynamic and informative dashboard.
- Embed Shiny apps to add interactivity, allowing users to filter data, adjust parameters, and explore visualizations dynamically.