'How to use shiny with check boxes from an excel file

I am trying to make a shiny app that all it does is display different line plots based on which check boxes are selected.

My data is housed in an excel file and it has 5 tabs, each of which I would like to have a plot and a corresponding check box. I have included a picture of the data enter image description here

I found the code below that creates checkboxes, but it also has a slider bar that I don't need (if I could use it, I would have it set the range of years to show in the plot)

Thanks for the help

library(ggplot2)
library(tidyverse)


df <- iris[, colnames(iris) != "Species"]

ui <- fluidPage(
  titlePanel("Density Plots of Quantitative Variables"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("bw", "Slide to change bandwidth of Plot",
        min = 0.1,
        max = 20,
        value = 3,
        step = 0.1,
        animate = TRUE
      ),
      checkboxGroupInput("variableinp", "Choose variables",
        choices = colnames(df), selected = colnames(df)[1]
      ), verbatimTextOutput("value")
    ),
    mainPanel(plotOutput("densityplot"))
  )
)


server <- function(input, output) {

  # observeEvent(input$variableinp, {
  #      print((input$variableinp))
  #  })

  output$densityplot <- renderPlot({
    if (!is.null(input$variableinp)) {
      getoutandquant <- function(x) {
        q1 <- quantile(x)[[2]]
        q3 <- quantile(x)[[4]]
        IQR <- q3 - q1

        out1 <- q3 + (1.5) * IQR
        out2 <- q1 - (1.5) * IQR

        # Finding the list of points which are outliers for a particular variable.
        out <- x[x > out1]
        out2 <- x[x < out2]
        outliers <- tibble(x = c(out, out2), y = 0)

        return(outliers)
      }
      nplot <- length(input$variableinp)
      x <- input$variableinp

      for (i in 1:nplot) {
        outlier <- getoutandquant(df[, x[i]])
      }

      p1 <- ggplot(df, aes_string(input$variableinp[i])) +
        stat_density(geom = "line", adjust = input$bw) +
        ylab("Density\n")
      p1 + geom_point(data = outlier, aes(x, y), shape = 23)
    }
  })
}


shinyApp(ui = ui, server = server)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source