R Shiny GGplot reactive graph not working

时间:2017-06-15 10:00:15

标签: r ggplot2 shiny

I'm trying to create a scatter plot in R shiny where the user selects X and Y from columns of a reactive combodf1() which was built from other reactives. If you set the input to x and y and the column names directly, it works, but setting them from input$metric_a etc (you can see the names of the choices and combodf1()'s cols are the same), the data is not present. Any help here would be really appreciated!

 Part of the UI:
          selectInput("metric_a", "metric_a:",
                      c("Buzz" = "buzz",
                        "Aided" = "aided",
                        "Adaware" = "adaware")),

          selectInput("metric_b", label = ("Metric B"), 
                  c("Buzz" = "buzz",
                    "Aided" = "aided",
                    "Adaware" = "adaware")),


Part of the server:

       combotest<- reactive({do.call(cbind, list(adaware()$Value, buzz()$Value, aided()$Value))})
      combodf<- reactive({as.data.frame(combotest())})
      # Renaming reactive cols - WORKS, PLYR function
      combodf1<-reactive({rename(combodf(), c("V1"="adaware", "V2"='buzz', 'V3' = 'aided'))})

      # PLOT 

      output$plot2<-renderPlot({
        ggplot(data=combodf1(),aes(x=input$metric_a,y=input$metric_b))+geom_point(colour='red')})

      }

1 个答案:

答案 0 :(得分:1)

找到解决方案,你必须使用:

!important中的aes_stringaes变量为x时,

y代替input$

希望这能节省一些时间!