20/02/2023

First Slide

Hi! This is a presentation for the coursera course: “Developing Data Products”

The presentation is structured as follows:

  • First I will present the ui.R Code
  • Second I will present the server.R Code
  • Finally I will present the shiny App

Slide With ui.R Code

Here is the ui.R code!

shinyUI(pageWithSidebar(
  headerPanel("Example plot"),
  sidebarPanel(
    sliderInput('mu', 'Guess at the mean',value = 25, min = 10, max = 35, step = 1,)
  ),
  mainPanel(
    plotOutput('newHist')
  )
))

Slide With server.R Code

Here is the server.R code!

data(mtcars)

shinyServer(
  function(input, output) {
    output$newHist <- renderPlot({
      hist(mtcars$mpg, xlab='miles per galon', col='lightblue',main='Histogram')
      mu <- input$mu
      mean_mpg <- mean(mtcars$mpg)
      lines(c(mu, mu), c(0, 35),col="red",lwd=5)
      lines(c(mean_mpg, mean_mpg), c(0, 35),col="green",lwd=5)
      mse <- mean((mtcars$mpg - mu)^2)
      text(12, 12, paste("mu = ", mu))
      text(12, 10,  paste("Mean = ",round(mean_mpg,2)))
      text(12, 8, paste("MSE = ", round(mse, 2)))
    })
  }
)

Slide With App