Motor Trend Fuel Economy Explorer

Djessi Jorge
31 July 2026

A reactive Shiny application for exploring vehicle trade-offs

  • Filter vehicles by horsepower, weight, cylinders and transmission
  • Compare observed fuel economy visually
  • Estimate MPG for a user-configured vehicle

Why this application?

The decision problem

Vehicle comparisons involve several linked characteristics. A heavier or more powerful car may offer different performance, but it may also use more fuel. Static tables make those trade-offs harder to explore.

The intended user

The application gives learners and analysts a simple way to:

  • narrow a comparison set with interactive controls;
  • see how weight and MPG relate;
  • inspect the vehicles behind each chart point; and
  • test a hypothetical vehicle configuration.

Data and reactive workflow

The application uses the built-in mtcars dataset, so it is reproducible without downloading an external file.

data(mtcars)
c(
  vehicles = nrow(mtcars),
  variables = ncol(mtcars),
  average_mpg = round(mean(mtcars$mpg), 1),
  mpg_range = paste(range(mtcars$mpg), collapse = " to ")
)
      vehicles      variables    average_mpg      mpg_range 
          "32"           "11"         "20.1" "10.4 to 33.9" 

Each widget change triggers a reactive filter. The summary cards, plot and vehicle table are recalculated from the same filtered records.

Model-backed prediction

The MPG predictor fits a transparent multiple linear regression:

mpg_model <- lm(mpg ~ wt + hp + factor(am), data = mtcars)
round(c(
  adjusted_R_squared = summary(mpg_model)$adj.r.squared,
  residual_SE = summary(mpg_model)$sigma
), 3)
adjusted_R_squared        residual_SE 
             0.823              2.538 

The user selects weight, horsepower and transmission. Shiny passes those inputs to predict(), displays the estimated MPG and plots it beside the observed vehicles. The result is illustrative because mtcars is a small, historical dataset.

Takeaway and project links

What the project demonstrates

  • Widget inputs linked to server-side calculations
  • Reactive filtering and model prediction
  • Multiple displayed outputs: metrics, plots and a table
  • On-site instructions, method notes and limitations
  • A complete workflow built with reproducible R code

Open the deliverables

Use the application to move from a broad vehicle list to an evidence-based, interactive comparison in seconds.