adding/removing traces in plotly per onclick event












2















I'm trying to print an interactive pie chart. On a click on the plot another trace should be added. I'm using event_data for this. When the trace is added, on the next click anywhere on the page the trace shall be removed. I didn't find a solution for that. I don't know how to overwrite the onclick-event after another click.



The next Problem would be to remove the before added trace. I think i could use plotlyProxy for that like in Removing traces by name using plotlyProxy (or accessing output schema in reactive context)



Afterwards you can see my code



library(shiny)
library(data.table)
library(plotly)

ui <- basicPage(
mainPanel(
fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
)
)

server <- function(input, output, session) {
testdata = data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
"Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
"Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
testdata = data.table(testdata)
testdata_agg = testdata[, sum(Umsatz.Orga), by=Dachorga]


output$myplot <- renderPlotly({
p <- testdata_agg %>%
group_by(Dachorga) %>%
plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
add_pie(hole = 0.6) %>%
layout(title = "Donut charts using Plotly", showlegend = F,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
d <- event_data("plotly_click")
if (!is.null(d)) {
p = add_pie(p, data = testdata[Dachorga == "Bla"], labels = ~Orga, values = ~Umsatz.Orga, hole = 0.5,
hoverinfo = 'label+percent+value', domain = list(
x = c(0.1, 0.9),
y = c(0.1, 0.9)),
marker = list(hover = list(color = "white")))
}
p
})
}

shinyApp(ui = ui, server = server)


Sorry for my bad english and thanks in advance










share|improve this question



























    2















    I'm trying to print an interactive pie chart. On a click on the plot another trace should be added. I'm using event_data for this. When the trace is added, on the next click anywhere on the page the trace shall be removed. I didn't find a solution for that. I don't know how to overwrite the onclick-event after another click.



    The next Problem would be to remove the before added trace. I think i could use plotlyProxy for that like in Removing traces by name using plotlyProxy (or accessing output schema in reactive context)



    Afterwards you can see my code



    library(shiny)
    library(data.table)
    library(plotly)

    ui <- basicPage(
    mainPanel(
    fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
    )
    )

    server <- function(input, output, session) {
    testdata = data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
    "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
    "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
    testdata = data.table(testdata)
    testdata_agg = testdata[, sum(Umsatz.Orga), by=Dachorga]


    output$myplot <- renderPlotly({
    p <- testdata_agg %>%
    group_by(Dachorga) %>%
    plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
    add_pie(hole = 0.6) %>%
    layout(title = "Donut charts using Plotly", showlegend = F,
    xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
    yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
    d <- event_data("plotly_click")
    if (!is.null(d)) {
    p = add_pie(p, data = testdata[Dachorga == "Bla"], labels = ~Orga, values = ~Umsatz.Orga, hole = 0.5,
    hoverinfo = 'label+percent+value', domain = list(
    x = c(0.1, 0.9),
    y = c(0.1, 0.9)),
    marker = list(hover = list(color = "white")))
    }
    p
    })
    }

    shinyApp(ui = ui, server = server)


    Sorry for my bad english and thanks in advance










    share|improve this question

























      2












      2








      2








      I'm trying to print an interactive pie chart. On a click on the plot another trace should be added. I'm using event_data for this. When the trace is added, on the next click anywhere on the page the trace shall be removed. I didn't find a solution for that. I don't know how to overwrite the onclick-event after another click.



      The next Problem would be to remove the before added trace. I think i could use plotlyProxy for that like in Removing traces by name using plotlyProxy (or accessing output schema in reactive context)



      Afterwards you can see my code



      library(shiny)
      library(data.table)
      library(plotly)

      ui <- basicPage(
      mainPanel(
      fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
      )
      )

      server <- function(input, output, session) {
      testdata = data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
      "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
      "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
      testdata = data.table(testdata)
      testdata_agg = testdata[, sum(Umsatz.Orga), by=Dachorga]


      output$myplot <- renderPlotly({
      p <- testdata_agg %>%
      group_by(Dachorga) %>%
      plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
      add_pie(hole = 0.6) %>%
      layout(title = "Donut charts using Plotly", showlegend = F,
      xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
      yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
      d <- event_data("plotly_click")
      if (!is.null(d)) {
      p = add_pie(p, data = testdata[Dachorga == "Bla"], labels = ~Orga, values = ~Umsatz.Orga, hole = 0.5,
      hoverinfo = 'label+percent+value', domain = list(
      x = c(0.1, 0.9),
      y = c(0.1, 0.9)),
      marker = list(hover = list(color = "white")))
      }
      p
      })
      }

      shinyApp(ui = ui, server = server)


      Sorry for my bad english and thanks in advance










      share|improve this question














      I'm trying to print an interactive pie chart. On a click on the plot another trace should be added. I'm using event_data for this. When the trace is added, on the next click anywhere on the page the trace shall be removed. I didn't find a solution for that. I don't know how to overwrite the onclick-event after another click.



      The next Problem would be to remove the before added trace. I think i could use plotlyProxy for that like in Removing traces by name using plotlyProxy (or accessing output schema in reactive context)



      Afterwards you can see my code



      library(shiny)
      library(data.table)
      library(plotly)

      ui <- basicPage(
      mainPanel(
      fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
      )
      )

      server <- function(input, output, session) {
      testdata = data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
      "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
      "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
      testdata = data.table(testdata)
      testdata_agg = testdata[, sum(Umsatz.Orga), by=Dachorga]


      output$myplot <- renderPlotly({
      p <- testdata_agg %>%
      group_by(Dachorga) %>%
      plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
      add_pie(hole = 0.6) %>%
      layout(title = "Donut charts using Plotly", showlegend = F,
      xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
      yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
      d <- event_data("plotly_click")
      if (!is.null(d)) {
      p = add_pie(p, data = testdata[Dachorga == "Bla"], labels = ~Orga, values = ~Umsatz.Orga, hole = 0.5,
      hoverinfo = 'label+percent+value', domain = list(
      x = c(0.1, 0.9),
      y = c(0.1, 0.9)),
      marker = list(hover = list(color = "white")))
      }
      p
      })
      }

      shinyApp(ui = ui, server = server)


      Sorry for my bad english and thanks in advance







      r shiny r-plotly






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 10:32









      M.K.M.K.

      203




      203
























          1 Answer
          1






          active

          oldest

          votes


















          2














          One can use a small javascript code to detect one click on the document, and send the result to the shiny server with Shiny.setInputValue. Then one can control the plot with the help of a reactive value.



          library(shiny)
          library(data.table)
          library(plotly)

          js <- "
          $(document).ready(function(){
          $(document).on('click', function(){
          Shiny.setInputValue('click_on_doc', true, {priority: 'event'});
          })
          })"

          ui <- basicPage(
          tags$head(tags$script(HTML(js))),
          mainPanel(
          fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
          )
          )

          server <- function(input, output, session) {
          testdata <- data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
          "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
          "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
          testdata <- data.table(testdata)
          testdata_agg <- testdata[, sum(Umsatz.Orga), by=Dachorga]

          plot <- testdata_agg %>%
          group_by(Dachorga) %>%
          plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
          add_pie(hole = 0.6) %>%
          layout(title = "Donut charts using Plotly", showlegend = F,
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

          click <- reactiveVal(FALSE)

          observe({
          event <- !is.null(event_data("plotly_click"))
          click(event)
          })

          observeEvent(input$click_on_doc, {
          click(FALSE)
          })

          output$myplot <- renderPlotly({
          if (click()) {
          p <- add_pie(plot, data = testdata[Dachorga == "Bla"], labels = ~Orga,
          values = ~Umsatz.Orga, hole = 0.5,
          hoverinfo = 'label+percent+value', domain = list(
          x = c(0.1, 0.9),
          y = c(0.1, 0.9)),
          marker = list(hover = list(color = "white")))
          }else{
          p <- plot
          }
          p
          })
          }

          shinyApp(ui = ui, server = server)


          I have not understood your "next problem". Perhaps open a new question and try to clarify.






          share|improve this answer


























          • Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

            – M.K.
            Nov 27 '18 at 10:34














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479204%2fadding-removing-traces-in-plotly-per-onclick-event%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          One can use a small javascript code to detect one click on the document, and send the result to the shiny server with Shiny.setInputValue. Then one can control the plot with the help of a reactive value.



          library(shiny)
          library(data.table)
          library(plotly)

          js <- "
          $(document).ready(function(){
          $(document).on('click', function(){
          Shiny.setInputValue('click_on_doc', true, {priority: 'event'});
          })
          })"

          ui <- basicPage(
          tags$head(tags$script(HTML(js))),
          mainPanel(
          fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
          )
          )

          server <- function(input, output, session) {
          testdata <- data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
          "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
          "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
          testdata <- data.table(testdata)
          testdata_agg <- testdata[, sum(Umsatz.Orga), by=Dachorga]

          plot <- testdata_agg %>%
          group_by(Dachorga) %>%
          plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
          add_pie(hole = 0.6) %>%
          layout(title = "Donut charts using Plotly", showlegend = F,
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

          click <- reactiveVal(FALSE)

          observe({
          event <- !is.null(event_data("plotly_click"))
          click(event)
          })

          observeEvent(input$click_on_doc, {
          click(FALSE)
          })

          output$myplot <- renderPlotly({
          if (click()) {
          p <- add_pie(plot, data = testdata[Dachorga == "Bla"], labels = ~Orga,
          values = ~Umsatz.Orga, hole = 0.5,
          hoverinfo = 'label+percent+value', domain = list(
          x = c(0.1, 0.9),
          y = c(0.1, 0.9)),
          marker = list(hover = list(color = "white")))
          }else{
          p <- plot
          }
          p
          })
          }

          shinyApp(ui = ui, server = server)


          I have not understood your "next problem". Perhaps open a new question and try to clarify.






          share|improve this answer


























          • Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

            – M.K.
            Nov 27 '18 at 10:34


















          2














          One can use a small javascript code to detect one click on the document, and send the result to the shiny server with Shiny.setInputValue. Then one can control the plot with the help of a reactive value.



          library(shiny)
          library(data.table)
          library(plotly)

          js <- "
          $(document).ready(function(){
          $(document).on('click', function(){
          Shiny.setInputValue('click_on_doc', true, {priority: 'event'});
          })
          })"

          ui <- basicPage(
          tags$head(tags$script(HTML(js))),
          mainPanel(
          fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
          )
          )

          server <- function(input, output, session) {
          testdata <- data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
          "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
          "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
          testdata <- data.table(testdata)
          testdata_agg <- testdata[, sum(Umsatz.Orga), by=Dachorga]

          plot <- testdata_agg %>%
          group_by(Dachorga) %>%
          plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
          add_pie(hole = 0.6) %>%
          layout(title = "Donut charts using Plotly", showlegend = F,
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

          click <- reactiveVal(FALSE)

          observe({
          event <- !is.null(event_data("plotly_click"))
          click(event)
          })

          observeEvent(input$click_on_doc, {
          click(FALSE)
          })

          output$myplot <- renderPlotly({
          if (click()) {
          p <- add_pie(plot, data = testdata[Dachorga == "Bla"], labels = ~Orga,
          values = ~Umsatz.Orga, hole = 0.5,
          hoverinfo = 'label+percent+value', domain = list(
          x = c(0.1, 0.9),
          y = c(0.1, 0.9)),
          marker = list(hover = list(color = "white")))
          }else{
          p <- plot
          }
          p
          })
          }

          shinyApp(ui = ui, server = server)


          I have not understood your "next problem". Perhaps open a new question and try to clarify.






          share|improve this answer


























          • Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

            – M.K.
            Nov 27 '18 at 10:34
















          2












          2








          2







          One can use a small javascript code to detect one click on the document, and send the result to the shiny server with Shiny.setInputValue. Then one can control the plot with the help of a reactive value.



          library(shiny)
          library(data.table)
          library(plotly)

          js <- "
          $(document).ready(function(){
          $(document).on('click', function(){
          Shiny.setInputValue('click_on_doc', true, {priority: 'event'});
          })
          })"

          ui <- basicPage(
          tags$head(tags$script(HTML(js))),
          mainPanel(
          fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
          )
          )

          server <- function(input, output, session) {
          testdata <- data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
          "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
          "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
          testdata <- data.table(testdata)
          testdata_agg <- testdata[, sum(Umsatz.Orga), by=Dachorga]

          plot <- testdata_agg %>%
          group_by(Dachorga) %>%
          plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
          add_pie(hole = 0.6) %>%
          layout(title = "Donut charts using Plotly", showlegend = F,
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

          click <- reactiveVal(FALSE)

          observe({
          event <- !is.null(event_data("plotly_click"))
          click(event)
          })

          observeEvent(input$click_on_doc, {
          click(FALSE)
          })

          output$myplot <- renderPlotly({
          if (click()) {
          p <- add_pie(plot, data = testdata[Dachorga == "Bla"], labels = ~Orga,
          values = ~Umsatz.Orga, hole = 0.5,
          hoverinfo = 'label+percent+value', domain = list(
          x = c(0.1, 0.9),
          y = c(0.1, 0.9)),
          marker = list(hover = list(color = "white")))
          }else{
          p <- plot
          }
          p
          })
          }

          shinyApp(ui = ui, server = server)


          I have not understood your "next problem". Perhaps open a new question and try to clarify.






          share|improve this answer















          One can use a small javascript code to detect one click on the document, and send the result to the shiny server with Shiny.setInputValue. Then one can control the plot with the help of a reactive value.



          library(shiny)
          library(data.table)
          library(plotly)

          js <- "
          $(document).ready(function(){
          $(document).on('click', function(){
          Shiny.setInputValue('click_on_doc', true, {priority: 'event'});
          })
          })"

          ui <- basicPage(
          tags$head(tags$script(HTML(js))),
          mainPanel(
          fluidRow(column(8, plotly::plotlyOutput("myplot", height = "800px")))
          )
          )

          server <- function(input, output, session) {
          testdata <- data.frame("Orga" = c("Li", "La", "Le", "Lu", "De", "Va", "Xul", "Jin"),
          "Dachorga" = c("Bla", "Bla", "Blu", "Blu", "Blub", "Blub", "Lol", "Lol"),
          "Umsatz.Orga" = c(20000, 10000, 12000, 3000, 100, 2400, 205000, 95000))
          testdata <- data.table(testdata)
          testdata_agg <- testdata[, sum(Umsatz.Orga), by=Dachorga]

          plot <- testdata_agg %>%
          group_by(Dachorga) %>%
          plot_ly(labels = ~Dachorga, values = ~V1, hoverinfo = 'label+percent+value') %>%
          add_pie(hole = 0.6) %>%
          layout(title = "Donut charts using Plotly", showlegend = F,
          xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
          yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

          click <- reactiveVal(FALSE)

          observe({
          event <- !is.null(event_data("plotly_click"))
          click(event)
          })

          observeEvent(input$click_on_doc, {
          click(FALSE)
          })

          output$myplot <- renderPlotly({
          if (click()) {
          p <- add_pie(plot, data = testdata[Dachorga == "Bla"], labels = ~Orga,
          values = ~Umsatz.Orga, hole = 0.5,
          hoverinfo = 'label+percent+value', domain = list(
          x = c(0.1, 0.9),
          y = c(0.1, 0.9)),
          marker = list(hover = list(color = "white")))
          }else{
          p <- plot
          }
          p
          })
          }

          shinyApp(ui = ui, server = server)


          I have not understood your "next problem". Perhaps open a new question and try to clarify.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 20:51

























          answered Nov 26 '18 at 20:17









          Stéphane LaurentStéphane Laurent

          16.3k75697




          16.3k75697













          • Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

            – M.K.
            Nov 27 '18 at 10:34





















          • Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

            – M.K.
            Nov 27 '18 at 10:34



















          Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

          – M.K.
          Nov 27 '18 at 10:34







          Thanks for your help. The "next Problem" is solved already with your code. I modified your javascript-code a bit by using information from <stackoverflow.com/questions/42996303/…>: <pre><code>js <- " $(document).ready(function(){ $(document).on('click', function(){ Shiny.setInputValue('click_on_doc', true, {priority: 'event'}); Shiny.setInputValue('.clientValue-plotly_click-A', 'null'); }) })"</code></pre>

          – M.K.
          Nov 27 '18 at 10:34






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479204%2fadding-removing-traces-in-plotly-per-onclick-event%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin