Fuel Efficiency Predictor

Da Le
2026-09-05

A simple Shiny application for estimating car fuel efficiency from vehicle weight, horsepower, and cylinders.

Why this app?

Fuel efficiency is easy to discuss but harder to estimate intuitively.

This app gives a novice user a simple way to ask:

  • How does weight affect expected MPG?
  • How does horsepower affect expected MPG?
  • How do 4-, 6-, and 8-cylinder vehicles compare?

The app is intentionally small, interactive, and easy to evaluate.

How the prediction works

The app uses the built-in mtcars dataset and fits a regression model in server.R.

model <- lm(mpg ~ wt + hp + factor(cyl), data = mtcars)
round(coef(model), 2)
 (Intercept)           wt           hp factor(cyl)6 factor(cyl)8 
       35.85        -3.18        -0.02        -3.36        -3.19 

The user's selections are passed into the model, and the predicted MPG is displayed reactively.

Interactive workflow

The Shiny interface includes three user inputs:

  • A slider for vehicle weight
  • A slider for horsepower
  • Radio buttons for cylinder count

When the user changes any input, the server recalculates the prediction and updates both the MPG estimate and the comparison chart.

Why it satisfies the assignment

  • The app has widget inputs.
  • server.R performs a real calculation on user input.
  • The calculated result is displayed in the web page.
  • Documentation is included inside the Shiny app itself.
  • This pitch contains embedded R code that is evaluated when the presentation is generated.

https://ld0574.shinyapps.io/fuel_efficiency_predictor/