| Title: | Add Bio Tooltips to HTML Reports |
|---|---|
| Description: | Provides lightweight helpers for adding gene and chemical tooltips to R Markdown, Quarto, Shiny, pkgdown, and other HTML outputs. The package emits small HTML spans with module-specific data attributes and attaches the browser-side 'bio-tooltips' JavaScript and CSS assets through 'htmltools'. Entity lookup and rendering are handled in the browser by 'bio-tooltips'; this package does not query biological databases from R during package checks. |
| Authors: | Matthew J. Meier [aut, cre] |
| Maintainer: | Matthew J. Meier <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-30 13:18:54 UTC |
| Source: | https://github.com/cran/BioTooltipR |
Experimental helper for reports where text has already been rendered. It injects a small browser script that scans selected DOM nodes and wraps a user-supplied vocabulary of gene symbols in Bio Tooltip spans.
auto_gene_tooltips( genes, species = "human", selector = "p, li, td", include_setup = TRUE, class = NULL )auto_gene_tooltips( genes, species = "human", selector = "p, li, td", include_setup = TRUE, class = NULL )
genes |
Character vector of gene symbols to wrap. |
species |
Species alias or NCBI taxonomy ID. |
selector |
CSS selector limiting where wrapping occurs. |
include_setup |
Include |
class |
Optional additional CSS class for generated spans. |
This is intentionally opt-in and vocabulary-limited because many gene symbols are ambiguous in prose.
An HTML tag list containing an optional setup tag and wrapping script.
auto_gene_tooltips(c("TP53", "BRCA1"), selector = ".results")auto_gene_tooltips(c("TP53", "BRCA1"), selector = ".results")
Low-level helper used by gene_tt() and chem_tt(). It emits an HTML
<span> with the classes and data-* attributes expected by the
JavaScript Bio Tooltips library.
bio_tooltip_span( label, type = c("gene", "chemical"), query = NULL, species = NULL, scope = NULL, lookup = NULL, class = NULL )bio_tooltip_span( label, type = c("gene", "chemical"), query = NULL, species = NULL, scope = NULL, lookup = NULL, class = NULL )
label |
Character vector of visible labels. |
type |
Tooltip type. One of |
query |
Optional lookup query. Mostly useful for chemical identifiers. |
species |
Gene species alias or NCBI taxonomy ID. |
scope |
Chemical lookup scope, such as |
lookup |
Optional chemical lookup mode, such as |
class |
Optional additional CSS class or full class string. If |
An HTML character vector with class html.
bio_tooltip_span("TP53", type = "gene", species = "human") bio_tooltip_span("aspirin", type = "chemical", query = "2244", scope = "pubchem")bio_tooltip_span("TP53", type = "gene", species = "human") bio_tooltip_span("aspirin", type = "chemical", query = "2244", scope = "pubchem")
Creates the htmltools dependency for the browser-side Bio Tooltips bundle.
bio_tooltips_dependency(cdn = FALSE, version = "1.1.1", local_path = NULL)bio_tooltips_dependency(cdn = FALSE, version = "1.1.1", local_path = NULL)
cdn |
Use jsDelivr CDN assets instead of the vendored package assets.
If |
version |
JavaScript package version. Use a pinned version for reproducible reports. |
local_path |
Optional path containing |
An htmltools::htmlDependency object.
Optional wrapper around DT::datatable() that disables HTML escaping by
default and re-initializes tooltips when the table redraws.
bt_datatable( data, ..., modules = c("gene", "chemical"), include_setup = TRUE, escape = FALSE )bt_datatable( data, ..., modules = c("gene", "chemical"), include_setup = TRUE, escape = FALSE )
data |
A data frame. |
... |
Passed to |
modules |
Tooltip modules to initialize. |
include_setup |
Include |
escape |
Passed to |
A DT widget, optionally wrapped in an HTML tag list.
Convenience helper for common omics reports. It optionally sorts and truncates a results data frame, annotates the gene column, and renders an HTML table.
bt_deg_table( data, gene_col = "symbol", species = "human", sort_by = NULL, decreasing = FALSE, n = NULL, ... )bt_deg_table( data, gene_col = "symbol", species = "human", sort_by = NULL, decreasing = FALSE, n = NULL, ... )
data |
A data frame containing differential-expression results. |
gene_col |
Gene-symbol column name. |
species |
Species alias or NCBI taxonomy ID. |
sort_by |
Optional column name used for sorting. |
decreasing |
Sort direction. |
n |
Optional number of rows to keep after sorting. |
... |
Passed to |
An HTML table with gene tooltip spans.
Wrapper around knitr::kable() that defaults to HTML output with escaping
disabled and optionally prepends use_bio_tooltips().
bt_kable( data, ..., modules = c("gene", "chemical"), include_setup = TRUE, format = "html", escape = FALSE )bt_kable( data, ..., modules = c("gene", "chemical"), include_setup = TRUE, format = "html", escape = FALSE )
data |
A data frame or object accepted by |
... |
Passed to |
modules |
Tooltip modules to initialize when |
include_setup |
Include |
format |
Table format. Defaults to |
escape |
Escape HTML? Defaults to |
An HTML tag list when setup is included; otherwise the result of
knitr::kable().
top_genes <- data.frame(symbol = c("TP53", "BRCA1")) top_genes <- gene_column(top_genes, symbol) bt_kable(top_genes)top_genes <- data.frame(symbol = c("TP53", "BRCA1")) top_genes <- gene_column(top_genes, symbol) bt_kable(top_genes)
bt_plotly_gene_hover() lets a Plotly widget use Bio Tooltips for gene
hover cards. Map the gene symbol into Plotly's key aesthetic, then wrap the
widget with this helper.
bt_plotly_gene_hover( plot, species = "human", gene_source = c("key", "customdata"), hide_plotly_hover = TRUE, include_setup = TRUE, class = NULL )bt_plotly_gene_hover( plot, species = "human", gene_source = c("key", "customdata"), hide_plotly_hover = TRUE, include_setup = TRUE, class = NULL )
plot |
A Plotly htmlwidget. |
species |
Species alias or NCBI taxonomy ID passed through to the generated gene tooltip span. |
gene_source |
Plotly point field containing the gene symbol. The default
uses |
hide_plotly_hover |
Suppress Plotly's native hover labels while keeping hover events active. |
include_setup |
Include |
class |
Optional additional CSS class added to the generated gene span. |
An HTML tag list containing the Plotly widget and a cursor-following Bio Tooltip anchor.
if (requireNamespace("plotly", quietly = TRUE)) { genes <- data.frame(symbol = c("TP53", "BRCA1"), x = 1:2, y = 2:3) plot <- plotly::plot_ly( genes, x = ~x, y = ~y, key = ~symbol, type = "scatter", mode = "markers" ) bt_plotly_gene_hover(plot, include_setup = FALSE) }if (requireNamespace("plotly", quietly = TRUE)) { genes <- data.frame(symbol = c("TP53", "BRCA1"), x = 1:2, y = 2:3) plot <- plotly::plot_ly( genes, x = ~x, y = ~y, key = ~symbol, type = "scatter", mode = "markers" ) bt_plotly_gene_hover(plot, include_setup = FALSE) }
Convenience wrapper around tooltip_column() for chemical labels.
chem_column( data, column, query_col = NULL, scope = NULL, scope_col = NULL, lookup = NULL, class = NULL )chem_column( data, column, query_col = NULL, scope = NULL, scope_col = NULL, lookup = NULL, class = NULL )
data |
A data frame. |
column |
Column to transform. May be unquoted or a single string. |
query_col |
Optional column containing stable lookup values. |
scope |
Chemical scope or scalar value recycled over rows. |
scope_col |
Optional column containing chemical scopes. |
lookup |
Optional chemical lookup mode. |
class |
Optional additional CSS class. |
data, with the selected column replaced by chemical tooltip HTML.
chemicals <- data.frame(name = "aspirin", cid = "2244") chem_column(chemicals, name, query_col = "cid", scope = "pubchem")chemicals <- data.frame(name = "aspirin", cid = "2244") chem_column(chemicals, name, query_col = "cid", scope = "pubchem")
chem_tt() vectorizes over chemical labels and emits HTML spans understood
by the Bio Tooltips MyChem.info module.
chem_tt(x, query = NULL, scope = NULL, lookup = NULL, class = NULL) chemical_tt(x, query = NULL, scope = NULL, lookup = NULL, class = NULL) chemical_tooltip(x, query = NULL, scope = NULL, lookup = NULL, class = NULL)chem_tt(x, query = NULL, scope = NULL, lookup = NULL, class = NULL) chemical_tt(x, query = NULL, scope = NULL, lookup = NULL, class = NULL) chemical_tooltip(x, query = NULL, scope = NULL, lookup = NULL, class = NULL)
x |
Character vector of visible chemical labels. |
query |
Optional stable lookup value. For example, use a PubChem CID
with |
scope |
Optional lookup scope, such as |
lookup |
Optional lookup mode, such as |
class |
Optional additional CSS class. |
An HTML character vector with class html.
chem_tt("aspirin", query = "2244", scope = "pubchem") chem_tt("caffeine", lookup = "best-guess")chem_tt("aspirin", query = "2244", scope = "pubchem") chem_tt("caffeine", lookup = "best-guess")
Convenience wrapper around tooltip_column() for gene symbols.
gene_column(data, column, species = "human", class = NULL)gene_column(data, column, species = "human", class = NULL)
data |
A data frame. |
column |
Column to transform. May be unquoted or a single string. |
species |
Species alias or NCBI taxonomy ID. |
class |
Optional additional CSS class. |
data, with the selected column replaced by gene tooltip HTML.
top_genes <- data.frame(symbol = c("TP53", "BRCA1")) gene_column(top_genes, symbol)top_genes <- data.frame(symbol = c("TP53", "BRCA1")) gene_column(top_genes, symbol)
gene_tt() vectorizes over gene symbols and emits HTML spans understood by
the Bio Tooltips MyGene.info module.
gene_tt(x, species = "human", class = NULL) gene_tooltip(x, species = "human", class = NULL)gene_tt(x, species = "human", class = NULL) gene_tooltip(x, species = "human", class = NULL)
x |
Character vector of gene symbols or labels. |
species |
Species alias such as |
class |
Optional additional CSS class. |
An HTML character vector with class html.
gene_tt("TP53") gene_tt(c("TP53", "BRCA1"), species = "human")gene_tt("TP53") gene_tt(c("TP53", "BRCA1"), species = "human")
Replaces a selected column with HTML tooltip spans. This is useful before
rendering with knitr::kable(escape = FALSE), bt_kable(), or another HTML
table system that can render unescaped HTML.
tooltip_column( data, column, type = c("gene", "chemical"), species = "human", query_col = NULL, scope = NULL, scope_col = NULL, lookup = NULL, class = NULL )tooltip_column( data, column, type = c("gene", "chemical"), species = "human", query_col = NULL, scope = NULL, scope_col = NULL, lookup = NULL, class = NULL )
data |
A data frame. |
column |
Column to transform. May be unquoted or a single string. |
type |
Tooltip type: |
species |
Species for gene tooltips. |
query_col |
Optional column containing chemical lookup values. |
scope |
Chemical scope or scalar value recycled over rows. |
scope_col |
Optional column containing chemical scopes. |
lookup |
Optional chemical lookup mode. |
class |
Optional additional CSS class. |
data, with the selected column replaced by HTML strings.
top_genes <- data.frame(symbol = c("TP53", "BRCA1"), padj = c(0.001, 0.02)) tooltip_column(top_genes, symbol, type = "gene")top_genes <- data.frame(symbol = c("TP53", "BRCA1"), padj = c(0.001, 0.02)) tooltip_column(top_genes, symbol, type = "gene")
Use this once in an R Markdown, Quarto, Shiny UI, or other HTML-producing context. It attaches the Bio Tooltips CSS/JS dependency and initializes the selected modules after the DOM is ready.
use_bio_tooltips( modules = c("gene", "chemical"), cdn = FALSE, version = "1.1.1", theme = "auto", prefetch = "smart", gene_selector = ".gene-tooltip", chemical_selector = ".chemical-tooltip", visual_preload = NULL, debug_timings = FALSE, tooltip_width = NULL, tooltip_height = NULL, include_optional_visual_deps = "auto", d3_version = "7.9.0", ideogram_version = "1.53.0", local_path = NULL )use_bio_tooltips( modules = c("gene", "chemical"), cdn = FALSE, version = "1.1.1", theme = "auto", prefetch = "smart", gene_selector = ".gene-tooltip", chemical_selector = ".chemical-tooltip", visual_preload = NULL, debug_timings = FALSE, tooltip_width = NULL, tooltip_height = NULL, include_optional_visual_deps = "auto", d3_version = "7.9.0", ideogram_version = "1.53.0", local_path = NULL )
modules |
Character vector containing |
cdn |
Use jsDelivr CDN assets instead of the vendored package assets.
See |
version |
JavaScript package version. Use a pinned version for reproducibility. |
theme |
Tooltip theme passed to Bio Tooltips. |
prefetch |
Prefetch strategy passed to Bio Tooltips. |
gene_selector |
CSS selector for gene tooltip elements. |
chemical_selector |
CSS selector for chemical tooltip elements. |
visual_preload |
Optional visual dependency warmup strategy for gene
visuals. Passed as |
debug_timings |
Log Bio Tooltips timing diagnostics in the browser. |
tooltip_width, tooltip_height
|
Optional tooltip dimensions. |
include_optional_visual_deps |
Include dependencies for D3 and
Ideogram. The default, |
d3_version, ideogram_version
|
Versions used when optional visual dependencies are included. |
local_path |
Optional local path for vendored Bio Tooltips assets. |
An HTML tag list containing dependencies and an initialization script.
use_bio_tooltips() use_bio_tooltips(modules = "gene", theme = "light")use_bio_tooltips() use_bio_tooltips(modules = "gene", theme = "light")