0

In this simple example:

library(shiny)
library(dplyr)
library(ggplot2)
df1 <-
  structure(
    list(
      V1 = structure(1:2, .Label = c("no", "yes"), class = "factor"),
      `Long Name 1` = c(27.74, 25.75), `Long Name 2` = c(30.36,
                                                         27.7)
    ), .Names = c("V1", "Long Name 1", "Long Name 2"), row.names = c(NA,-2L), class = "data.frame"
  )


server <- function(input, output) {
  output$plot <- renderPlot({
    vrble <- as.name(input$select)
    df1 %>% ggplot(aes(x = V1, y = vrble, fill = V1)) +
      geom_bar(stat = "identity") +
      guides(fill = FALSE) + theme_bw() +
      scale_fill_brewer(palette = "Set1") +
      scale_y_continuous(limits = c(0,30), breaks = round(seq(min(0), max(30), by = 5),1))


  })
}

ui <- fluidPage(sidebarLayout(sidebarPanel(
  width = 3,
  selectInput(
    "select", label = h3("Variable"),
    choices = names(df1)[2:3],
    selected = 1
  )
),
mainPanel(plotOutput("plot"))))

shinyApp(ui = ui, server = server)

I get the following error:

Error in data.frame(x = structure(1:2, .Label = c("no", "yes"), class = "factor"),  : 
                      object 'Long Name 1' not found
                    Error in data.frame(x = structure(1:2, .Label = c("no", "yes"), class = "factor"),  : 
                                          object 'Long Name 2' not found

How can I fix it?

Ignacio
  • 7,646
  • 16
  • 60
  • 113
  • 1
    You likely need `aes_string` instead of `aes` - something like `aes_string(x = "V1", y = vrble, fill = "V1")` – aosmith Sep 08 '15 at 17:40
  • @aosmith Thanks! that did the trick. Nothing to do with dplyr, my brain was half-asleep while writing the – Ignacio Sep 08 '15 at 17:44

0 Answers0