2024-08-05

Executive Summary

What is this?

This is a shiny application and reproducible pitch for it. It is the final project for the John Hopkins Building Data Products Course.

What does it do?

This app converts Celsius to Fahrenheit and plots the difference.

Why do I need this?

Easy temperature conversion! - Interactive, dynamic, and easy to use! - It’s FREE!

Celsius to Fahrenheit Converter

Appendix 1 - Code Used

This is the UI function within the app.R code

library(shiny)
# Define UI 
ui <- fluidPage(
    # Application title
    titlePanel("Celsius to Fahrenheit Converter"),
    # Sidebar 
    sidebarLayout(
        sidebarPanel(
          numericInput("tempC", "Temperature in Celsius:", value = 0)
        ),
        # Show a plot of the generated distribution
        mainPanel(
           textOutput("tempFahrenheit"),
           plotOutput("tempPlot")
        )
    )
)

Appendix 2 - Code Used

This is the Server function within the app.R code - Part 1

# Define server logic
server <- function(input, output) 
{
  # Reactive expression to calculate Fahrenheit temperature
  tempF <- reactive(
    {input$tempC * 9/5 + 32})
  
  # Render text output 
  output$tempFahrenheit <- renderText(
    {
    tempF <- input$tempC * 9/5 + 32
    paste("Temperature in Fahrenheit:", tempF())
    })

Appendix 3 - Code Used

This is the Server function within the app.R code - Part 2
    # Render double line plot
    output$tempPlot <- renderPlot({
    # Define the range for x-axis
    x_range <- c(0, max(input$tempC, tempF()) + 10)
    # Plot setup
    plot(
      c(0, x_range[2]), c(0, 100), type = "n",
      xlab = "Temperature", ylab = "Temperature", 
      main = "Temperature Comparison",
      ylim = c(min(input$tempC, tempF()) - 10, max(input$tempC, tempF()) + 10)
    )
    # Add horizontal lines
    abline(h = input$tempC, col = "blue", lty = 1, lwd = 2)
    abline(h = tempF(), col = "red", lty = 2, lwd = 2)
    # Add x-axis labels for the temperature values
    axis(1, at = c(input$tempC, tempF()), labels = c(paste0(input$tempC, " °C"), paste0(tempF(), " °F")))
    # Add a legend
    legend("topright", legend = c("Celsius", "Fahrenheit"), col = c("blue", "red"), lty = c(1, 2), lwd = 2)
  })
   
} #End Server

# Run the application 
shinyApp(ui = ui, server = server)

Appendix 4 - Code Used

This is the embedded code for the markdown presentation

library(htmltools)

# Where I host the app
app_url <- "https://josephbloomquist.shinyapps.io/tempConverter/"

# Embed the Shiny app using an iframe
tags$iframe(src = app_url, width = "100%", height = "600px", frameborder = "0")