A 'Shiny' Application for Inspecting Structural Topic Models

This app enables interactive validation, interpretation and visualization of structural topic models from the 'stm' package by Roberts and others (2014) . It also includes helper functions for model diagnostics and extracting data from effect estimates.

Travis-CI BuildStatus AppVeyor BuildStatus CRANstatus CRANdownloads

A Shiny Application for Structural Topic Models

This app enables interactive validation, interpretation and visualisation of Structural Topic Models (STM). Stminsights is focused on making your life easier after fitting your STM models. In case you are not familiar with STM, the package vignette is an excellent starting point.

How to Install

You can download and install the latest development version of the app by running devtools::install_github('cschwem2er/stminsights').

For Windows users installing from github requires proper setup of Rtools, for which a tutorial is available here.

stminsights can also be installed from CRAN by running install.packages('stminsights').

How to Use

After loading stminsights you can launch the shiny app in your browser:


You can then upload a .RData file which should include:

  • one or several stm objects.
  • one or several estimateEffect objects.
  • an object out which was used to fit your stm models.

As an example, the following code fits two models and estimates effects for the Political Blog Corpus. Afterwards, all objects required for stminsights are stored in stm_poliblog5k.RData.

out <- list(documents = poliblog5k.docs,
            vocab = poliblog5k.voc,
            meta = poliblog5k.meta)
poli <- stm(documents = out$documents, 
            vocab = out$vocab,
            data = out$meta, 
            prevalence = ~ rating * s(day),
            K = 20)
prep_poli <- estimateEffect(1:20 ~ rating * s(day), poli,
                            meta = out$meta)
poli_content <-  stm(documents = out$documents, 
                     vocab = out$vocab,
                     data = out$meta, 
                     prevalence = ~ rating + s(day),
                     content = ~ rating,
                     K = 15)  
prep_poli_content <- estimateEffect(1:15 ~ rating + s(day), poli_content,
                                    meta = out$meta)

After launching stminsights and uploading the file, all objects are automatically imported and you can select which models and effect estimates to analyze.

In addition to the shiny app, several helper functions are available, e.g. get_effects() for storing effect estimates in a tidy dataframe.

How to Deploy on Shiny Server

Deploying stminsights to your own shiny server is simple: Place the file app.R, which is located at inst/app of this package, to a folder in your server directory and you should be good to go.


Please cite stminsights if you use it for your publications:

  Carsten Schwemmer (2018). stminsights: A Shiny Application for Inspecting
  Structural Topic Models. R package version 0.3.0.

A BibTeX entry for LaTeX users is:

    title = {stminsights: A Shiny Application for Inspecting Structural Topic Models},
    author = {Carsten Schwemmer},
    year = {2018},
    note = {R package version 0.3.0},
    url = {https://github.com/cschwem2er/stminsights},


stminsights 0.3.0

New features implemented by Jonne Guyt

  • representative documents are now searchable
  • representative document table now contains (optional) information on: row id, STM document ID and theta
  • proportions can now be plotted for each individual document using the STM document ID
  • documents can be plotted in a (clickable) 2d scatter plot that shows proportions on two topics simultaneously
  • document information displayed upon clicking scatter plot

Minor improvements

  • popup texts moved such that inputs can be selected more easily
  • default options for document inspection changed

stminsights 0.2.3

Minor improvements

  • multiple variables can now be selected for inspecting representative documents of topics

stminsights 0.2.2

Update Dependencies

  • updated package dependencies to fix installation errors

stminsights 0.2.1

Bug Fix

  • fixed a bug for storing topic labels in a spreadsheet
  • increased the number of documents for inspecting topics

stminsights 0.2.0

Minor improvements

  • include vignette for an introduction to stminsights
  • include url for bug reports
  • update readme

stminsights 0.1.2

Minor improvements / Bug Fix / CRAN Release

stminsights 0.1.1

Minor improvements

  • added option for labeling axes
  • added more options for content model term selection

stminsights 0.1.0

First release

  • This is the first release of the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.4.1 by Carsten Schwemmer, a month ago


Report a bug at https://github.com/cschwem2er/stminsights/issues

Browse source code at https://github.com/cran/stminsights

Authors: Carsten Schwemmer [aut, cre] , Jonne Guyt [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports stm, tidygraph, ggraph, igraph, ggrepel, shiny, shinyBS, shinydashboard, shinyjs, ggplot2, purrr, stringr, dplyr, tibble, readr, huge, stats, scales

Suggests quanteda, knitr, rmarkdown

See at CRAN