Title: | Build SVG Custom User Interface |
---|---|
Description: | Render SVG as interactive figures to display contextual information, with selectable and clickable user interface elements. These figures can be seamlessly integrated into 'rmarkdown' and 'Quarto' documents, as well as 'shiny' applications, allowing manipulation of elements and reporting actions performed on them. Additional features include pan, zoom in/out functionality, and the ability to export the figures in SVG or PNG formats. |
Authors: | Patrice Godard [aut, cre, cph] |
Maintainer: | Patrice Godard <[email protected]> |
License: | GPL-3 |
Version: | 0.1.5 |
Built: | 2024-11-03 04:05:50 UTC |
Source: | https://github.com/patzaw/bscui |
Add an SVG element to the UI
add_bscui_element(proxy, id, svg_txt, ui_type = NULL, title = NULL)
add_bscui_element(proxy, id, svg_txt, ui_type = NULL, title = NULL)
proxy |
a |
id |
the identifier of the element to add (will replace the id attribute of the provided svg if any) |
svg_txt |
a character with SVG code of one element and its children |
ui_type |
either "selectable", "button" or "none". If NULL (default), the element won't be available as UI |
title |
a description of the element to display on mouseover event |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Build SVG Custom User Interface
bscui( svg_txt, sanitize_attributes = TRUE, width = NULL, height = NULL, elementId = NULL )
bscui( svg_txt, sanitize_attributes = TRUE, width = NULL, height = NULL, elementId = NULL )
svg_txt |
a character with SVG code |
sanitize_attributes |
logical indicating if '<' and '>' characters in element attributes must be replaced by text |
width , height
|
widget width: must be a valid CSS unit (like |
elementId |
hmtl identifier of the widget |
An htmlwidget
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Output and render functions for using bscui within 'shiny' applications.
bscuiOutput(outputId, width = "100%", height = "400px") renderBscui(expr, env = parent.frame(), quoted = FALSE)
bscuiOutput(outputId, width = "100%", height = "400px") renderBscui(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 bscui |
env |
The environment in which to evaluate |
quoted |
Is |
The bscuiProxy()
function can be used to allow user interface dynamic
updates.
An output or render function that enables the use of the widget within 'shiny' applications.
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Manipulate an existing bscui instance in a 'shiny' app
bscuiProxy(shinyId, session = shiny::getDefaultReactiveDomain())
bscuiProxy(shinyId, session = shiny::getDefaultReactiveDomain())
shinyId |
single-element character vector indicating the 'shiny' output ID of the UI to modify |
session |
the 'shiny' session object to which the UI belongs; usually the default value will suffice |
This function creates a proxy object that can be used to manipulate an existing bscui instance in a 'shiny' app using different methods:
update_bscui_ui_elements: change type and title of elements
update_bscui_styles: set style of UI elements
update_bscui_attributes set attributes of a UI element
update_bscui_selection: chose selected elements
click_bscui_element: trigger a single or double click on a UI element
order_bscui_elements: change elements order (e.g. move them forward)
add_bscui_element: add an SVG element to the UI
remove_bscui_elements: remove SVG elements from the UI
get_bscui_svg: get the displayed SVG in R session
A bscui_Proxy
object with an "id" and a "session" slot.
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Trigger a click event on a clickable element
click_bscui_element(proxy, element_id, dbl_click = FALSE)
click_bscui_element(proxy, element_id, dbl_click = FALSE)
proxy |
a |
element_id |
element identifier on which the click will be triggered |
dbl_click |
logical indicating the type of click (default: FALSE => single click is triggered) |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Save a bscui widget to an image file
export_bscui_to_image( widget, file, selector = ".bscui", zoom = 1, quiet = TRUE, ... )
export_bscui_to_image( widget, file, selector = ".bscui", zoom = 1, quiet = TRUE, ... )
widget |
a |
file |
name of output file. Should end with an image file type (.png, .jpg, .jpeg, or .webp) or .pdf. |
selector |
( |
zoom |
( |
quiet |
( |
... |
additional parameters for |
Invisibly returns the normalized path to the image. The character vector will have a class of "webshot".
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Get the displayed SVG
get_bscui_svg(proxy)
get_bscui_svg(proxy)
proxy |
a |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Change element order in the SVG
order_bscui_elements( proxy, element_ids, where = c("front", "back", "forward", "backward") )
order_bscui_elements( proxy, element_ids, where = c("front", "back", "forward", "backward") )
proxy |
a |
element_ids |
the identifiers of the element to move |
where |
where to move the elements (default: "front") |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Remove SVG elements from the UI
remove_bscui_elements(proxy, element_ids)
remove_bscui_elements(proxy, element_ids)
proxy |
a |
element_ids |
the identifiers of the elements to remove |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Set attributes of elements of a bscui widget
set_bscui_attributes( widget, element_attributes, to_ignore = NULL, targeted_tags = widget$x$structure_shapes, append = FALSE )
set_bscui_attributes( widget, element_attributes, to_ignore = NULL, targeted_tags = widget$x$structure_shapes, append = FALSE )
widget |
a |
element_attributes |
a data frame with an id column providing the element identifier and one column per attribute name. |
to_ignore |
identifiers of elements to ignore: if those elements are children of elements to update they won't be updated |
targeted_tags |
targeted_tags affected tag names (by default: structure_shapes of the scui object) |
append |
if TRUE the value will be concatenate with the existing value |
The modified bscui
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Set options of bscui widget
set_bscui_options( widget, show_menu, menu_width, zoom_min, zoom_max, zoom_step, clip, default_png_scale, selection_color, selection_opacity, selection_width, hover_color, hover_opacity, hover_width, structure_shapes, dblclick_timeout, hover_timeout, width, height )
set_bscui_options( widget, show_menu, menu_width, zoom_min, zoom_max, zoom_step, clip, default_png_scale, selection_color, selection_opacity, selection_width, hover_color, hover_opacity, hover_width, structure_shapes, dblclick_timeout, hover_timeout, width, height )
widget |
a |
show_menu |
if TRUE (default) control menu will be available |
menu_width |
css width value (default: "30px") |
zoom_min |
smallest zoom value (default: 0.5) |
zoom_max |
largest zoom value (default: 20) |
zoom_step |
zooming step: the larger the faster (default: 1.1) |
clip |
if TRUE (default: FALSE), when the current zoom is 1, the viewBox is automatically set to its original state (the drawing cannot be moved) |
default_png_scale |
default value for scaling PNG export (default: 1) |
selection_color |
color used to highlight selection (default: "orange") |
selection_opacity |
opacity of selection highlight (default: 0.5) |
selection_width |
the additional stroke width to apply on selection (default: 4) |
hover_color |
a list of colors used to highlight hovered elements
(default: |
hover_opacity |
opacity of hovered highlight (default: 0.5) |
hover_width |
the additional stroke width to apply on hover (default: 4) |
structure_shapes |
SVG shapes to considered as concrete
drawing
(default:
|
dblclick_timeout |
minimum time in ms between 2 independant clicks (default: 250) |
hover_timeout |
time in ms before update hovered element (default: 100) |
width , height
|
widget width: must be a valid CSS unit (like |
The modified bscui
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Pre-select UI elements in a bscui widget
set_bscui_selection(widget, selected)
set_bscui_selection(widget, selected)
widget |
a |
selected |
identifiers of pre-selected identifiers |
The modified bscui
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Set styles of elements of a bscui widget
set_bscui_styles( widget, element_styles, to_ignore = NULL, targeted_tags = widget$x$structure_shapes, append = FALSE )
set_bscui_styles( widget, element_styles, to_ignore = NULL, targeted_tags = widget$x$structure_shapes, append = FALSE )
widget |
a |
element_styles |
NULL or a data frame with an id column providing the element identifier and one column per style name. Column names should correspond to a style name in camel case (e.g., "strokeOpacity"). |
to_ignore |
identifiers of elements to ignore: if those elements are children of elements to update they won't be updated |
targeted_tags |
targeted_tags affected tag names (by default: structure_shapes of the scui object) |
append |
if TRUE the value will be concatenate with the existing value |
The modified bscui
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Set UI elements of a bscui widget
set_bscui_ui_elements(widget, ui_elements)
set_bscui_ui_elements(widget, ui_elements)
widget |
a |
ui_elements |
NULL or a data frame with the following columns:
|
The modified bscui
object
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
##################################@ ### Preparing data ---- library(bscui) library(xml2) library(readr) library(dplyr) svg <- xml2::read_xml(system.file( "examples", "Animal_cells.svg.gz", package="bscui" )) info <- readr::read_tsv(system.file( "examples", "uniprot_cellular_locations.txt.gz", package="bscui" ), col_types=strrep("c", 6)) |> mutate(id = sub("-", "", `Subcellular location ID`)) ##################################@ ### Building the figure ---- figure <- bscui(svg) |> set_bscui_ui_elements( info |> mutate( ui_type = "selectable", title = Name ) |> select(id, ui_type, title) ) |> set_bscui_styles( info |> filter(Name == "Cytosol") |> mutate(fill = "#FF7F7F") |> select(id, fill) ) |> set_bscui_attributes( info |> filter(Name == "Cytoskeleton") |> mutate(display = "none") |> select(id, display) ) |> set_bscui_selection("SL0188") |> set_bscui_options(zoom_min=1, clip=TRUE) figure ##################################@ ### Saving the figure ---- if(interactive()){ ## Temporary directory to save example file tdir <- tempdir() ## Interactive html file f_path <- file.path(tdir, "figure.html") figure |> htmlwidgets::saveWidget(file=f_path) cat(f_path) ## PNG image f_path <- file.path(tdir, "figure.png") figure |> set_bscui_options(show_menu = FALSE) |> export_bscui_to_image(file=f_path, zoom=2) cat(f_path) }
Update the attributes of bscui elements in 'shiny' app
update_bscui_attributes( proxy, element_attributes, to_ignore = NULL, targeted_tags = NULL )
update_bscui_attributes( proxy, element_attributes, to_ignore = NULL, targeted_tags = NULL )
proxy |
a |
element_attributes |
a data frame with an id column providing the element identifier and one column per attribute name. |
to_ignore |
of elements to ignore: if those elements are children of elements to update they won't be updated. This parameter is not taken into account when there is no "id" column in the element_styles data frame. |
targeted_tags |
affected tag names. If NULL (default),
the structure_shapes of the |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Replace current selection with given element identifiers
update_bscui_selection(proxy, element_ids)
update_bscui_selection(proxy, element_ids)
proxy |
a |
element_ids |
element identifiers to add to the selection; empty clear the selection |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Update the style of bscui elements in 'shiny' app
update_bscui_styles( proxy, element_styles, to_ignore = NULL, targeted_tags = NULL, append = FALSE )
update_bscui_styles( proxy, element_styles, to_ignore = NULL, targeted_tags = NULL, append = FALSE )
proxy |
a |
element_styles |
a data frame with an "id" column and one column per style to apply. If the "id" column is missing, then the modifications apply to the svg selected elements. |
to_ignore |
of elements to ignore: if those elements are children of elements to update they won't be updated. This parameter is not taken into account when there is no "id" column in the element_styles data frame. |
targeted_tags |
affected tag names. If NULL (default),
the structure_shapes of the |
append |
if TRUE the value will be concatenate with the existing value |
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
Update the type and title of bscui ui elements in 'shiny' app
update_bscui_ui_elements(proxy, ui_elements)
update_bscui_ui_elements(proxy, ui_elements)
proxy |
a |
ui_elements |
NULL or a data frame with the following columns:
|
the provided proxy object
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }
if(interactive()){ from_shiny <- new.env() shiny::runApp(system.file( "examples", "shiny-anatomogram", package = "bscui" )) for(n in names(from_shiny)){ bscui(from_shiny[[n]]) |> print() } }