2022-10-16

##Agenda

Daily World Oil Consumption

This Shiny app presents the daily oil consumption of two hundred and fourteen countries. By using a slider selector, the user can select a range of ranked countries to dynamically present them in the web frame.

Use the following link to use the Daily World Oil Consumption shiny app;

https://vicct.shinyapps.io/DailyWorldOilConsumption/

The slider selector

The slider selector lets users select the countries ranked in the different positions. The user can select the initial and the final rank of countries to be displayed in the plot.

The plotted information

According to the range selected in the slider, the plot area will present the countries with the following information: The name of the country, the level of the country in the graphic and the number of oil barrels daily consumed. The graphic illustrates the Ranking versus the Daily Oil Consumption (Barrels).

Server calculations

The server.R file calculates the list of Countries selected based on the minX & maxX ranking range selected. The data information is accessed from an CSV file with the daily oil consumption information.

library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
  
  output$text1 = renderText(input$OilConsumptionSlider)
  output$plot1 <- renderPlot({
    set.seed(2016-05-25)
    minX <- input$OilConsumptionSlider[1]
    maxX <- input$OilConsumptionSlider[2]
    data <- read.csv("WorldOilStats.csv", header=TRUE)
    str(data)
    ylab <- "Daily Oil Consumption (Barrels)"
    xlab <- "Ranking"
    main <- "World Oil Consumption"
    plot(data$Ranking, data$DOC, xlab = xlab, ylab = ylab, xlim = c(minX, maxX))
    with(data[minX:maxX,],text(data$Ranking, data$DOC, labels = (data[minX:maxX,2,]), pos = 3))
    with(data[minX:maxX,],text(data$Ranking, data$DOC, labels = (data[minX:maxX,3,]), pos = 4))
  })
})