Extract NEW Traces from Plotly

I'd like to:

  • render a plot to display

*allow the user to change features using something like plotlyProxy()

*extract those values for other calculations to potentially use.
This code doesn't do this job but this is the kind of thing I'm trying to do!


ui <- fluidPage(
  h4("addTraces", style = "text-decoration: underline;"),
    textInput("xvalue", NULL, "1,2,3,4"),
    textInput("yvalue", "Add more Y values" , "3,3,3,3"),
  actionButton("add", "Add", width = '210px'),


server <- function(input, output, session) {
  #The plot output and send the data to global environment
  output$p <- renderPlotly({
   out <- plot_ly(
     type = 'scatter',
      mode = 'markers',
      x = c(1,2,3,4), 
      y = c(2,4,2,4)
    ) %>%
        showlegend = T)
   plotly_get_data <<- plotly_build(out)
  # plotly.addTraces. plotlyProxy takes an outputID not a plotly object so not clear 
#if can use this and then still extract the Y values for use by other functions
  observeEvent(input$add, {
    plotlyProxy("p", session) %>%
      plotlyProxyInvoke("addTraces", list(x = as.integer(unlist(strsplit(input$xvalue,","))), 
                                          y = as.integer(unlist(strsplit(input$yvalue, ","))),
                                          type = 'scatter',
                                          mode = 'markers'))
  #view the data generated
  output$sum_ys <- renderText({
    paste("The y values on this graph are: ",

shinyApp(ui, server)

Any help would be MUCH appreciated!

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