This document details how to make LDAvis react to shiny inputs. In theory, any createJSON() argument could be dynamically altered in a shiny app or interactive document. In practice, this might not be such a great idea since createJSON() can take a few seconds to run (note in this example it's about 5 seconds).

Anyway, here is one way to alter the number of terms shown using a shiny::sliderInput().

library(shiny)
sliderInput("nTerms", "Number of terms to display", min = 20, max = 40, value = 30)

By wrapping a call to createJSON() with renderVis(), the output will update whenever the value of input$nTerms changes.

library(LDAvis)
data(TwentyNewsgroups, package = "LDAvis")
renderVis({
  with(TwentyNewsgroups, 
       createJSON(phi, theta, doc.length, vocab, term.frequency, 
                  R = input$nTerms))
})


cpsievert/LDAvis documentation built on May 13, 2019, 10:54 p.m.