g2r supports crosstalk to link g2 visualisations with other htmlwidgets that supports crosstalk.

Warning

Crosstalk only works with data passed to g2.

Filter

For instance, one can add a g2 plot to an example from the plotly R book.

library(g2r)
library(plotly)
library(crosstalk)

# plotly
tx <- highlight_key(txhousing)

# filter widgets
widgets <- htmltools::div(
  filter_select("city", "Cities", tx, ~city),
  filter_slider("sales", "Sales", tx, ~sales),
  filter_checkbox("year", "Years", tx, ~year, inline = TRUE)
)

# arrange
bscols(
  widths = c(2, 5, 5),
  widgets, 
  plot_ly(tx, x = ~date, y = ~median, showlegend = FALSE) %>% 
    add_lines(color = ~city, colors = "black"),
  g2(tx, asp(date, median, color = city), digits = 16) %>% 
    fig_line() %>% 
    legend_color(FALSE)
)