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)
library(ggplot2)
# 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? And basically how do reactive plots work?
@gergeli. Your code problem just the data table pass to ggplot is not right. The concept of ggplot is column based, so you cannot use the two selectInput directly as the arguments of aes because they are not the column name. You have to use the two selectInput to tidy your data and made the useful data in column. For example, I select Australia, Bangladesh and Argentina in input$selects and Attribute1 and Attribute2 in input$selects2. The data pass to ggplot will like the following.