dfr_browser | R Documentation |
Export model data and all supporting files needed to browse a model or models interactively using dfr-browser, then (optionally) open a web browser. It is also possible to browse a list of models.
dfr_browser(m, ...)
m |
|
... |
passed on to |
out_dir |
directory for output. By default, files are saved to a temporary directory. |
browse |
if TRUE, launch web browser after export for viewing (requires servr package). |
internalize |
always set to FALSE. If TRUE, model data is in the browser home page rather than separate files, but this behavior is deprecated. See Details. |
overwrite |
if TRUE (default), overwrite any pre-existing files. |
condition |
dfr-browser displays topic proportions conditioned on (bins
of) a chosen metadata variable (by default, publication date). Any variable
in |
info |
dfr-browser configuration object (see
|
sub_info |
list of lists of browser configurations (multiple-model
display only). The elements of this list should have names corresponding to
|
metadata_header |
if TRUE (FALSE is default), the exported metadata CSV will have a header row (not expected by dfr-browser by default, but see the example below) |
ids |
character vector. If multiple models are specified in |
insert_alignment_table |
if |
If browse=T
, the function attempts to start a local webserver and
open a web browser pointing to the appropriate URL. This functionality
requires the servr
package.
For more control over the export, including the option to export data files
only, if for example you have modified the HTML/CSS/JS of an existing
dfr-browser, use export_browser_data
(q.v.).
dfr-browser can be configured to retrieve data from more than one model, or
to show topic proportions in a single model conditioned on more than one
metadata variable, or both. dfr_browser
can generate the necessary
data and configuration files. Passing dfr_browser
a list of model
objects will generate a single dfr-browser with a menu for swapping among
the models. Passing a single mallet_model
and a vector of variable
names as condition
will generate a dfr-browser with a menu for
swapping among covariates (internally, dfr-browser treats these two
possibilities the same). Passing both a list of models and a vector of
variable names will generate all the model-covariate pairs. Passing a list
of models and a list of the same length of variable names will use the
corresponding element of condition
as the chosen covariate options
for the given model. Finally, in place of a list of models, you can supply
the result of align_topics
. In that case the topics in each
model are relabeled according to their assigned cluster number. It is
possible to achieve the same result more manually by passing a list of
models and specifying a topic_ids
vector for each model in the
sub_info
parameter.
internalize=TRUE
will cause all model data to be stored in the
index.html file, whence it can be loaded by dfr-browser. This behavior is no
longer useful; the model data should always be exported as separate files
for asynchronous loading by dfr-browser. (In former days one could avoid
having to launch a web server and simply point a browser at the index.html
file. dfr-browser no longer works in this circumstance because it relies on
a Web Worker, which modern web browsers will refuse to load from a
file:///
URL.)
export_browser_data
which does the work of exporting
files, model_dfr_documents
, train_model
,
topic_scaled_2d
## Not run: m <- model_dfr_documents("citations.CSV", "wordcounts", "stoplist.txt", n_topics=40) # launch browser dfr_browser(m) # generate a second model and align its topics with the first for more # convenient comparisons m2 <- model_dfr_documents("citations.CSV", "wordcounts", "stoplist.txt", n_topics=40) cl <- model_distances(list(m, m2), n_words=40) %>% align_topics() dfr_browser(m2, permute=match(cl$clusters[[1]], cl$clusters[[2]]))) # or simply: dfr_browser(cl) # create a browser that allows you to toggle among 2 metadata variables dfr_browser(m, condition=c("pubdate", "journaltitle")) # create a browser for metadata in a non-DfR format; note info specification dfr_browser(m, condition="something_else", metadata_header=T, info=list(VIS=list( metadata=list(type="base"), bib=list(type="base"), bib_view=list(major="all", minor="raw") )), ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.