1

I am new to Shiny and I've been struggling with the following. In the ui I define a set of variables that users can choose. However, when I call upon the input variable the correct label for the variable displays on the x-axis but there is no data. When I change the input$variable to any of the actual variable names, the correct results display. What am I doing wrong?

 output$analysis1 <- renderPlot({
  df <- m1
  df <- subset(df, df$rcid %in% unique(Select_voting()$rcid))

  ggplot(subset(df,  unsc_region == 'Latin America'), aes(x = input$variable, y = reorder(CountryAbb, input$variable),
                                                         color = ordvote)) +
    geom_point(size=3)  + theme_light() + ggtitle("Latin America") + scale_colour_manual(values=vcolors)

})
Erik V
  • 11
  • 2
  • Please, provide a minimal reproducible example. – Icaro Bombonato Dec 20 '16 at 17:01
  • 1
    Welcome to the stackoverflow community. Please don't forget to follow the [tour](http://stackoverflow.com/tour) and if possible, read [that article](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to ask a question with a reproducible exemple. – YCR Dec 20 '16 at 17:02
  • You aren't really providing us with enough information (i.e. it works when you switch to an "actual variable name" - what else could possibly go there?). It sounds like an simple data issue though, nothing particular to Shiny. – Mike Wise Dec 20 '16 at 20:11
  • I think it may be a ggplot issue. If I use geo_string – Erik V Dec 20 '16 at 22:03
  • What I meant is that if I replace input$variable with any variable name in the aes() I get the correct graph but if I leave input$variable I just see the variable name on the axis. I think it may be a ggplot issue. If I use geo_string I get data but then the reorder and color parts of the aes function don't work because it no longer recognizes factors. I'd appreciate a work around. – Erik V Dec 20 '16 at 22:08
  • Oh. You need to use `aes_string` if you are specifying the variable names as strings. Which you are if you are using `input$variable`. Should have seen that. Search this site for examples. – Mike Wise Dec 20 '16 at 22:12
  • 1
    I think I have figured it out. Apologies, was unaware of aes_string in ggplot2. – Erik V Dec 20 '16 at 22:19
  • Can't know everything :). At least to start with. – Mike Wise Dec 20 '16 at 22:33
  • To be fair, I really don't see why `ggplot2` can't catch that itself. It does much harder things routinely. – Mike Wise Dec 20 '16 at 22:37

0 Answers0