The LDAvis package in R creates a visualisation of a topic modelling analysis using LDA with the serVis function. If you save this visualisation you end up with a folder with css and html files.
json <- createJSON(
phi = tmResult$terms,
theta = tmResult$topics,
doc.length = rowSums(as.matrix(dtm)),
vocab = colnames(as.matrix(dtm)),
term.frequency = colSums(as.matrix(dtm)),
plot.opts = list(xlab = "", ylab = "")
serVis(json, out.dir = 'LDAvis', open.browser = FALSE)
If you open the index.html file, you get a blank page due to browser restrictions. For a more elaborate description read:
LDAvis HTML output from serVis is blank
The easiest solution is to change the browser restrictions. However, I want to share this visual with 100+ people. It is not feasable to ask them all to change their browser setting.
In the Python version (PyDavis) it is easily solved by creating a standalone html page, which can easily be shared.
Export pyLDAvis graphs as standalone webpage
Is there a way to get a standalone html version of the serVis visual using R?
EDIT: reproducable data/script:
# Install and load required packages
library(LDAvis)
library(tm)
library(topicmodels)
# Set seed for reproducibility
set.seed(123)
# Create fake data
documents <- c("This is the first document.",
"The second document is here.",
"And this is the third one.",
"Is this the first document?")
# Create a Document-Term Matrix
corpus <- Corpus(VectorSource(documents))
dtm <- DocumentTermMatrix(corpus)
#lda
num_topics <- 3
topicModel <- LDA(dtm, k = num_topics, control = list(seed = 9999))
tmResult <- posterior(topicModel)
# Create fake JSON data
json <- createJSON(
phi = tmResult$terms,
theta = tmResult$topics,
doc.length = rowSums(as.matrix(dtm)),
vocab = colnames(as.matrix(dtm)),
term.frequency = colSums(as.matrix(dtm)),
plot.opts = list(xlab = "", ylab = "")
)
# Save fake visualization to a folder
serVis(json, out.dir = 'test', open.browser = TRUE)

Update
I have created a pull request to add a
stand.aloneargument toserVis(). Until this request is merged in, you could install the updatepak::pkg_install("the-mad-statter/LDAVis")and then runserVis(json, out.dir = 'test', open.browser = TRUE, stand.alone = TRUE).Otherwise, I think you have three options here:
1. Enable CORS
Instruct your recipients to enable CORS in their browers. However, this is not recommended as:
2. Host
Host the R outputed files somewhere. Some options include:
3. Retool
Retool the {LDAvis} package files.
The following script is a bit hackish, but it does succeed in collating all of the individual files inline into a new standalone index2.html document as desired.