plotly proxy updating before action button is clicked, cannot change colors

I'm trying to create a graph that adds a point to a graph anytime a user uses the action button. Currently, the graph updates before the user clicks the action button. I also can't seem to get the colors to change within the plot. Thanks for any guidance!

        output$plot <- renderPlotly({
            isolate({
                x <- list(
                    title = "N Leaching [lbs/ac]"
                )
                y <- list(
                    title = "Yield"
                )
                plot <- plot_ly(
                    x = vals$Leachable,
                    y = vals$Yield, 
                    type = 'scatter',
                    mode = 'markers',
                    marker = list(size = 10, color = brewer.pal(10,"Set3")),
                ) 
                plot <- plot %>% layout(xaxis = x, yaxis = y)
                plot
            })  
        })
 #Server end of clear page button       
observeEvent(input$reset_button, {js$reset()})
               
        
      # Takes N Leaching and Yield values and plots them
observeEvent(input$action,{
        observeEvent(c(vals$Leachable, vals$Yield), {
            plotlyProxy("plot",session) %>%
                plotlyProxyInvoke("addTraces", 
                                  list(x = c(vals$Leachable,vals$Leachable), # need at least 2 points
                                       y = c(vals$Yield,vals$Yield),
                                       type = "scatter",
                                       mode = "markers",
                                       marker = list(size=10),
                                       color = brewer.pal(10, 'Set3')
                                       
                                  )
                )
        })
    })

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.