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)