November 7, 2020

Presentation

Server

This is the code for the server file. It fills the population variable from the data file (csv)

library(shiny)

# Load Data

population <- read.csv("./usPopulation.csv")

# This is our shiny server
function(input, output) { 
  
  output$number_of_people <- renderPlot({ 
    
    # Plotting a barplot 
    barplot(population[,input$State],  
            main=input$State, 
            ylab="Count of People", 
            xlab="Year") 
  })
}

UI

This is the code for the UI which accepts data from the server while passing it inputs from a select input.

library(shiny)


# Loading the data about mexican population state wise in USA

population <- read.csv("./usPopulation.csv")


fluidPage(     
  
  # Give the page a title 
  titlePanel("Population per state"), 
  
  sidebarLayout(       
    
    
    # A sidebar for input 
    sidebarPanel(selectInput("State", "State:",  
                             choices=colnames(population)), 
                 hr(), 
    ), 
    
    mainPanel( 
      plotOutput("number_of_people")   
    ) 
    
  ) 
) 

Conclusion

We can use the shiny app to view this in action!