58

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?

Community
  • 1
  • 1
Ziyuan
  • 4,215
  • 6
  • 48
  • 77
  • Did you try the [rCharts](https://github.com/ramnathv/rCharts) package to create Javascript "charts" from R ? This is easily embeddable in a Shiny App. – Stéphane Laurent Jun 24 '13 at 17:49
  • @StéphaneLaurent I've noticed this package but this question is asked before its invention. – Ziyuan Jun 24 '13 at 20:00
  • I'm pretty sure I have seen yesterday an interactive ggplot on [Timely Portfolio blog](http://timelyportfolio.blogspot.fr/) but I have not been able to find it again today. – Stéphane Laurent Aug 11 '13 at 11:37

1 Answers1

2

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")
  }

)
mgriebe
  • 908
  • 5
  • 8