Data explorer template for R Shiny

Pick a dataset and two columns to get a scatter plot, a searchable DT table and a summary, with axis choices that update per dataset. Free R Shiny template.

The Data explorer template in the DropToApp editor: the app's layout with its inputs and outputs
The template in the DropToApp editor. Run it to see it working.

About this template

A small exploratory data analysis tool. Choose one of R’s built-in datasets, pick the columns for the X and Y axes, and switch between a scatter plot, an interactive table and a summary in tabs.

The axis menus are filled from the server with updateSelectInput(), so they always list the numeric columns of the chosen dataset. Add your own data frames to the list in the setup code.

What's inside

  • Inputs that update each other with observe() and updateSelectInput()
  • A tabbed card (navset_card_tab()) with plot, table and summary tabs
  • An interactive, searchable table with DT::DTOutput()
  • An optional trend line from lm(), switched with a checkbox
  • req() to wait until the inputs are valid

The complete app.R

Download
# Generated by DropToApp
library(shiny)
library(bslib)

# Datasets that come with R
datasets <- list(
  "Cars (mtcars)" = mtcars,
  "Flowers (iris)" = iris,
  "Earthquakes (quakes)" = quakes,
  "Air quality (airquality)" = airquality
)

ui <- page_sidebar(
  title = "Data explorer",
  sidebar = sidebar(
    selectInput("dataset", "Dataset", choices = names(datasets)),
    selectInput("x", "X axis", choices = NULL),
    selectInput("y", "Y axis", choices = NULL),
    checkboxInput("trend", "Add a trend line")
  ),
  navset_card_tab(
    nav_panel("Plot", plotOutput("scatter")),
    nav_panel("Table", DT::DTOutput("table")),
    nav_panel("Summary", verbatimTextOutput("summary"))
  )
)

server <- function(input, output, session) {
  # Inputs: input$dataset, input$x, input$y, input$trend

  data <- reactive(datasets[[input$dataset]])

  # Offer the numeric columns of the chosen dataset as axes
  observe({
    numeric_cols <- names(Filter(is.numeric, data()))
    updateSelectInput(session, "x", choices = numeric_cols, selected = numeric_cols[1])
    updateSelectInput(session, "y", choices = numeric_cols, selected = numeric_cols[2])
  })

  output$scatter <- renderPlot({
    d <- data()
    req(input$x %in% names(d), input$y %in% names(d))
    plot(d[[input$x]], d[[input$y]], xlab = input$x, ylab = input$y,
         pch = 19, col = "#007bc288")
    if (input$trend) abline(lm(d[[input$y]] ~ d[[input$x]]), col = "#e74c3c", lwd = 2)
  })

  output$table <- DT::renderDT({
    data()
  })

  output$summary <- renderPrint({
    summary(data())
  })
}

shinyApp(ui, server)

How to run it

  1. In your browser: run it with shinylive. R runs on your computer with webR; the first start downloads R and the packages, which can take a minute.
  2. In R or RStudio: save the code as app.R, install the packages once with install.packages(c("shiny", "bslib", "DT")), then run shiny::runApp() in the folder with the file.
  3. In DropToApp: open the template in the editor to change the layout by drag and drop or edit the code, and export your own app.R.

More Shiny templates

Screenshot of the KPI dashboard Shiny template in the DropToApp editor

KPI dashboard

A Shiny dashboard with KPI value boxes, sidebar filters, a chart and a top-5 table, built with bslib on R’s airquality data. Free app.R to copy, edit and run.

DashboardValue boxesFilters
Screenshot of the Feedback form Shiny template in the DropToApp editor

Feedback form

A feedback form in R Shiny: text, choice and rating inputs, a conditional field, validation, a live table of responses and a CSV download. Free app.R.

FormsValidationDownload
Screenshot of the Multi-page app Shiny template in the DropToApp editor

Multi-page app

A Shiny app with several pages in a navigation bar: an overview with value boxes and an accordion, an interactive plotly chart and a DT data table.

Multi-pagePlotlyAccordion
Screenshot of the CSV upload and explorer Shiny template in the DropToApp editor

CSV upload and explorer

Upload a CSV file, choose the separator, and see its rows, columns, a searchable table and a summary. Download the data again as CSV. Free Shiny app template.

File uploadDT tableDownload
Screenshot of the Histogram explorer Shiny template in the DropToApp editor

Histogram explorer

The classic first Shiny app, rebuilt with bslib: a slider and a variable picker drive a histogram of the Old Faithful geyser data. Free app.R to copy and run.

BeginnerCharts