ggiraph in shiny

ggiraph is an htmlwidget. It can be used within a Shiny application. In shiny, elements associated with data_id can be selected and the selection (the data_id value) is available in the client and the server side of the application.

The client ui.R

Instead of a plotOutput, use function ggiraphOutput.


The server server.R

Use function ggiraphOutput.

output$plot <- renderggiraph({
    ggiraph(code = print(gg_blahblah) )


It is possible to work with selecteds point on a ggiraph plot within a Shiny application.

Selection can be of two types: single or multiple. The ggiraph’s parameter selection_type will let you specify that.

output$myplot <- renderggiraph({
    ggiraph(code = print(gg_blahblah), selection_type = "multiple" )

The selected points will be captured in the input reactive value myplot_selected (name of the input id of the reactive output value + _selected):


You can also modify theses values by using the session$sendCustomMessage method with type myplot_set (name of the input id of the reactive output value + _set).

# delete selection
session$sendCustomMessage(type = 'myplot_set', message = character(0))


The package contains Shiny examples available in the shiny directory of the package (system.file("shiny", package = "ggiraph")).

crimes and cars applications demonstrate multiple and single selections usage.

shiny::runApp(appDir = system.file("shiny/crimes", package = "ggiraph"), display.mode = "showcase")
shiny::runApp(appDir = system.file("shiny/cars", package = "ggiraph"), display.mode = "showcase")

DT demonstrates how to use onclick actions on the client side.

shiny::runApp(appDir = system.file("shiny/DT", package = "ggiraph"), display.mode = "showcase")

iris demonstrates behavior of selections when some data_id are duplicated.

shiny::runApp(appDir = system.file("shiny/iris", package = "ggiraph"), display.mode = "showcase")