vendredi 1 juillet 2016

User specified fill

I am using ggvis and have the following code with a selectInput on the UI side allowing the user to select which variable dictates fill and shape (inputId is fill and shape respectively). I want the plot to have the ability to have a constant fill or shape should the user choose. The else section of this code works exactly how I want, but when I select the option in the if statement the app crashes with the following error:

Error in eval: could not find function ":="

I know I have the syntax correct because if I suppress the legends and the if/else statement and specify the fill as constant (fill := "black") it works how I want it to.

Any help would be appreciated.

vis <- reactive({
fillvar <- prop("fill", as.symbol(input$fill))
shapevar <- prop("shape", as.symbol(input$shape))
ggvis(x = xvar, y = yvar) %>%
  layer_points(size.hover := 200,
               fillOpacity:= 0.5, fillOpacity.hover := 1,

               # Allows for points to be consistent if the user desires

               if (input$fill == "All Points Black") {
                 fill := "black"}
               else {
                 fill = fillvar}
               ,

               if (input$shape == "All Points Circles") {
                 shape := "circle"}
               else {
                 shape = shapevar}
              ,

               key := ~ID
  ) %>%

  # Adds legends to the Plot in designated locations
  add_legend("fill", title = as.character(fillvar)) %>%
  add_legend("shape", title = as.character(shapevar), properties = legend_props(legend = list(y=300))) %>%

  # Adds the previously defined tool_tip my_tooltip
  add_tooltip(my_tooltip, "hover") %>%

  # Specifies the size of the plot
  set_options(width = 800, height = 400, duration = 0)
})

#Actually plots the data
vis %>% bind_shiny("plot1")

Aucun commentaire:

Enregistrer un commentaire