highlighted_browser: Convert tokens into full texts in an HTML file with...

Description Usage Arguments Value Examples

View source: R/tokenvis.r

Description

Convert tokens into full texts in an HTML file with highlighted tokens

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
highlighted_browser(
  tokens,
  value,
  meta = NULL,
  col = "yellow",
  doc_col = "doc_id",
  token_col = "token",
  doc_nav = NULL,
  token_nav = NULL,
  filename = NULL,
  unfold = NULL,
  span_adjacent = T,
  ...
)

Arguments

tokens

A data.frame with a column for document ids (doc_col) and a column for tokens (token_col)

value

Either a logical vector or a numeric vector with values between 0 and 1. If a logical vector is used, then tokens with TRUE will be highlighted (with the color specified in pos_col). If a numeric vector is used, the value determines the alpha (transparency), with 0 being fully transparent and 1 being fully colored.

meta

A data.frame with a column for document_ids (doc_col). All other columns are added to the browser as document meta

col

The color used to highlight

doc_col

The name of the document id column

token_col

The name of the token column

doc_nav

The name of a column in meta, used to set a navigation tag

token_nav

Alternative to doc_nav, a column in the tokens, used to set a navigation tag

filename

Name of the output file. Default is temp file

unfold

Either a character vector or a named list of vectors of the same length as tokens. If given, all tokens with a tag can be clicked on to unfold the given text. If a list of vectors is given, the values of the columns are concatenated with the column name. E.g. list(doc_id = 1, sentence = 1) will be [doc_id = 1, sentence = 2].

span_adjacent

If TRUE, include adjacent tokens with identical attributes within the same tag

...

Additional formatting arguments passed to create_browser()

Value

The name of the file where the browser is saved. Can be opened conveniently from within R using browseUrl()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## as an example, highlight words based on word length
highlight = nchar(as.character(sotu_data$tokens$token))
highlight = highlight / max(highlight)
highlight[highlight < 0.3] = NA
url = highlighted_browser(sotu_data$tokens, value = highlight, sotu_data$meta)


view_browser(url)   ## view browser in the Viewer

if (interactive()) {
browseURL(url)     ## view in default webbrowser
}

tokenbrowser documentation built on Oct. 23, 2020, 6:54 p.m.