Title: | Pick Data Points from a Deck.gl Scatterplot |
---|---|
Description: | Performant interactive scatterplot for ~ 1 million points. Zoom, pan, and pick points. Includes tooltips, labels, a grid overlay, legend, and coupled interactions across multiple plots. |
Authors: | Alex Pickering [aut, cre] |
Maintainer: | Alex Pickering <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.6 |
Built: | 2025-03-03 02:47:17 UTC |
Source: | https://github.com/hms-dbmi/picker |
Render a Picker Widget
picker( coords, colors, labels, title = NULL, label_coords = NULL, polygons = NULL, point_color_polygons = NULL, show_controls = TRUE, grid_legend_items = NULL, scale_legend_props = NULL, scatter_props = NULL, deck_props = NULL, text_props = NULL, polygon_props = NULL, xrange = NULL, yrange = NULL, xaxs = 0.04, yaxs = 0.04, width = NULL, height = NULL, elementId = NULL )
picker( coords, colors, labels, title = NULL, label_coords = NULL, polygons = NULL, point_color_polygons = NULL, show_controls = TRUE, grid_legend_items = NULL, scale_legend_props = NULL, scatter_props = NULL, deck_props = NULL, text_props = NULL, polygon_props = NULL, xrange = NULL, yrange = NULL, xaxs = 0.04, yaxs = 0.04, width = NULL, height = NULL, elementId = NULL )
coords |
data.frame with two columns. First has x, second has y coordinates. |
colors |
vector of hex colors, one for each row of |
labels |
vector of point labels used for tooltips on hover. |
title |
character string to show in top left of plot. |
label_coords |
data.frame with three columns 'x', 'y', and 'label'. Used for text layer. |
polygons |
data.frame containing at minimum columns 'x1', 'x2', 'y1', 'y2', that define the polygons to draw and 'color' that defines the color. |
point_color_polygons |
character, a color to make points when polygons are shown e.g. |
show_controls |
Should control panel be shown? Default is |
grid_legend_items |
list of lists with |
scale_legend_props |
optional props to render a gradient scale legend.
For example: |
scatter_props |
Props passed to deck.gl ScatterplotLayer. |
deck_props |
Props passed to deck.gl Deck instance. |
text_props |
Props passed to deck.gl TextLayer. |
polygon_props |
Props passed to deck.gl PolygonLayer. |
xrange |
range of x-values. Default is |
yrange |
range of y-values. Default is |
xaxs |
the fraction to extend |
yaxs |
the fraction to extend |
width |
width of htmlwidget. |
height |
height of htmlwidget. |
elementId |
id of htmlwidget. |
renders html widget
if (interactive()) { library(shiny) library(picker) # load example data load(system.file('extdata/pbmcs.rda', package = 'picker')) # setup gradient scale legend scale_legend_props <- list( colorHigh = 'blue', colorLow = '#f5f5f5', high = round(max(exp)), low = min(exp)) text_props <- list() # get colors for gene expression exp <- scales::rescale(exp, c(0, 1)) expression_colors <- scales::seq_gradient_pal('#f5f5f5', 'blue')(exp) # legend to show when grid is visible grid_legend_items = list( list(color = '#FF0000', label = '\U2191'), list(color = '#0000FF', label = '\U2193'), list(color = '#989898', label = 'p \U003C .05'), list(color = '#EAEAEA', label = 'p \U2265 .05') ) ui = shinyUI(fluidPage( tags$head(tags$style(".picker {border: 1px solid #ddd; margin: 20px 0;}")), shiny::column( width = 6, pickerOutput('clusters', width = '100%', height = '400px'), pickerOutput('expression', width = '100%', height = '400px'), verbatimTextOutput('selected') ) )) server = function(input, output) { # show selected output output$selected <- renderPrint({ input$clusters_selected_points }) # coordinate views (zoom/pan) clusters_proxy <- picker_proxy('clusters') observeEvent(input$expression_view_state, { update_picker(clusters_proxy, input$expression_view_state) }) expression_proxy <- picker_proxy('expression') observeEvent(input$clusters_view_state, { update_picker(expression_proxy, input$clusters_view_state) }) # change title between grid/scatterplot observeEvent(input$clusters_show_grid, { title <- ifelse(input$clusters_show_grid, '\U0394 CELLS', '') update_picker(clusters_proxy, title = title) }) # render pickers output$clusters <- renderPicker( picker( coords, cluster_colors, labels, label_coords = label_coords, polygons = polygons, text_props = text_props, point_color_polygons = 'white', grid_legend_items = grid_legend_items) ) output$expression <- renderPicker( picker(coords, expression_colors, labels, show_controls = FALSE, scale_legend_props = scale_legend_props) ) } shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE)) }
if (interactive()) { library(shiny) library(picker) # load example data load(system.file('extdata/pbmcs.rda', package = 'picker')) # setup gradient scale legend scale_legend_props <- list( colorHigh = 'blue', colorLow = '#f5f5f5', high = round(max(exp)), low = min(exp)) text_props <- list() # get colors for gene expression exp <- scales::rescale(exp, c(0, 1)) expression_colors <- scales::seq_gradient_pal('#f5f5f5', 'blue')(exp) # legend to show when grid is visible grid_legend_items = list( list(color = '#FF0000', label = '\U2191'), list(color = '#0000FF', label = '\U2193'), list(color = '#989898', label = 'p \U003C .05'), list(color = '#EAEAEA', label = 'p \U2265 .05') ) ui = shinyUI(fluidPage( tags$head(tags$style(".picker {border: 1px solid #ddd; margin: 20px 0;}")), shiny::column( width = 6, pickerOutput('clusters', width = '100%', height = '400px'), pickerOutput('expression', width = '100%', height = '400px'), verbatimTextOutput('selected') ) )) server = function(input, output) { # show selected output output$selected <- renderPrint({ input$clusters_selected_points }) # coordinate views (zoom/pan) clusters_proxy <- picker_proxy('clusters') observeEvent(input$expression_view_state, { update_picker(clusters_proxy, input$expression_view_state) }) expression_proxy <- picker_proxy('expression') observeEvent(input$clusters_view_state, { update_picker(expression_proxy, input$clusters_view_state) }) # change title between grid/scatterplot observeEvent(input$clusters_show_grid, { title <- ifelse(input$clusters_show_grid, '\U0394 CELLS', '') update_picker(clusters_proxy, title = title) }) # render pickers output$clusters <- renderPicker( picker( coords, cluster_colors, labels, label_coords = label_coords, polygons = polygons, text_props = text_props, point_color_polygons = 'white', grid_legend_items = grid_legend_items) ) output$expression <- renderPicker( picker(coords, expression_colors, labels, show_controls = FALSE, scale_legend_props = scale_legend_props) ) } shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE)) }
Creates a picker-like object that can be used to update a picker object that has already been rendered.
picker_proxy(shinyId, session = shiny::getDefaultReactiveDomain())
picker_proxy(shinyId, session = shiny::getDefaultReactiveDomain())
shinyId |
single-element character vector indicating the output ID of the deck to modify |
session |
the |
a picker_proxy
object that can be updated with update_picker
.
Output and render functions for using picker within Shiny applications and interactive Rmd documents.
pickerOutput(outputId, width = "100%", height = "400px") renderPicker(expr, env = parent.frame(), quoted = FALSE)
pickerOutput(outputId, width = "100%", height = "400px") renderPicker(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a picker |
env |
The environment in which to evaluate |
quoted |
Is |
An output or render function that enables the use of the widget within Shiny applications.
Shiny
appSend commands to a picker instance in a Shiny
app
update_picker( proxy, view_state = NULL, colors = NULL, labels = NULL, label_coords = NULL, polygons = NULL, point_color_polygons = NULL, show_grid = NULL, title = NULL )
update_picker( proxy, view_state = NULL, colors = NULL, labels = NULL, label_coords = NULL, polygons = NULL, point_color_polygons = NULL, show_grid = NULL, title = NULL )
proxy |
picker proxy object created by |
view_state |
view state from other picker input (optional). |
colors |
vector of hex colors, one for each row of |
labels |
vector of point labels used for tooltips on hover. |
label_coords |
data.frame with three columns 'x', 'y', and 'label'. Used for text layer. |
polygons |
data.frame containing at minimum columns 'x1', 'x2', 'y1', 'y2', that define the polygons to draw and 'color' that defines the color. |
point_color_polygons |
character, a color to make points when polygons are shown e.g. |
show_grid |
set to |
title |
character string to show in top left of plot. |
The original proxy
object. Called for side effects.