Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204771

What is the simplest way to make an interactive bar plot with multiple drop down filters with Shiny and ggplot combo?

$
0
0

I know it sounds a bit basic, but I would like to make an interactive barplot which can handle multiple x and y axis whether the user would like to use it.

I started it like this way however I know there are many things which are need to be added.

library(dplyr)
library(shiny)

# Sample workable data

sample <- data.frame("Country" = c("Australia", "Bangladesh",
                                     "Argentina", "Slovakia", "Greece", "Sweden"),
                       "Attribute1" = 57:62,
                       "Attribute2" = 13:18,
                       "Attribute3" = 5:10)

# Since I cannot enter the choices one by one..

Atts <- sample %>%
  select(Attribute1:Attribute3) %>%
  names() 

Ctrs <- unique(sample$Country)


# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Sample Drop Down"),

  # Sidebar with dropdown

  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = "selects", choices = Ctrs,
                  label = "Select Region", multiple = TRUE),
      selectInput(inputId = "selects2", choices = Atts, label = "select attribute",
                  multiple = TRUE)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("Plot")
    )
  )
)



# Define server logic required to draw a histogram
server <- function(input, output) {

  output$Plot <- renderPlot({
    ggplot(data = sample, aes(x = input$selects, y= input$selects2)) + 
      geom_bar(stat = "identity", color = "blue", fill = "Country")
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

So how do I link the UI and Server part together?


Viewing all articles
Browse latest Browse all 204771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>