9  Shiny and ggiraph reactive values

The graphic is transformed into a reactive object and three set of inputs (events and selections) are available, those of the panel elements, those of the legend elements and those of the theme elements.

9.1 Shiny usage

  • Register used fonts with register_gfont()
  • add a call to addGFontHtmlDependency(family = c(...)) in the ui part
  • add a placeholder for the ‘ggiraph’ graphic in the ui part with girafeOutput("plot").
  • add a render component in the server part with renderGirafe(girafe(ggobj = ...)).

9.1.1 Selection as a reactive value

Three reactive values are available:

  • the selection of the data_id of the panel, selected elements will be captured in the input reactive value girafeid_selected (name of the input id of the reactive output value + _selected).
  • the selection of the data_id of the legend elements, selected elements will be captured in the input reactive value girafeid_key_selected (name of the input id of the reactive output value + _key_selected).
  • the selection of the data_id of the theme elements, selected elements will be captured in the input reactive value girafeid_theme_selected (name of the input id of the reactive output value + _theme_selected).
input$plot_selected
input$plot_key_selected
input$plot_theme_selected

9.1.2 Update selected values from Shiny

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

# delete selections
session$sendCustomMessage(type = 'plot_set', message = character(0))
session$sendCustomMessage(type = 'plot_key_set', message = character(0))
session$sendCustomMessage(type = 'plot_theme_set', message = character(0))