Use D3 and Shiny to implement `identify()` in R

JavascriptRd3.jsShiny

Javascript Problem Overview


I asked a question on how to plot dynamically according to user interactions, whose solution works quite well on my machine.

Now I want to make an on-line version and host it with Shiny.

I have tried to put the code into server.R and invoke the iden() function inside reactivePlot(), but the part of identify() does not take effect.

So, any hints on this task?

Javascript Solutions


Solution 1 - Javascript

Try this gallery item. It uses ggvis to accomplish this goal in shiny. In case the gallery disappears, here is some minimal code that will produce a tooltip, similar to identify(), using ggvis.

require(ggvis)
mtcars$model<-rownames(mtcars)
mtcars %>% ggvis(~wt, ~mpg,key:=~model) %>% 
  layer_points() %>% 
  add_tooltip(function(df) df$model)

And, a more complete, but still minimal example:

require(shiny)
require(ggvis)
mtcars$model<-rownames(mtcars)

shinyApp(
  ui = fluidPage(
    sidebarLayout(
      sidebarPanel(h2("GGVis to Identify Points")),
      mainPanel(ggvisOutput("carsplot"))
    )
  ), 
  server = function(input, output) {
    vis <- reactive({ 
      mtcars %>% ggvis(~wt, ~mpg,key:=~model) %>% 
        layer_points() %>% 
        add_tooltip(function(df) df$model)
    })
    vis %>% bind_shiny("carsplot")
  }

)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZiyuanView Question on Stackoverflow
Solution 1 - JavascriptmgriebeView Answer on Stackoverflow