下面的代码是我用于在闪亮的应用程序中使用 topic_model 函数中的 text2vec 绘制 LDA 图的代码。input$date 是一个 checkboxGroupInput 选择, input$data 非常适合 DT::renderDataTable 输出和 topic_model 在应用程序之外运行良好。在这里,我找到了如何在一个闪亮的应用程序中获得 LDA 图,但我并没有真正得到它,因为它是被复制的。input$go 是一个简单的 actionButton。
raw_data <- eventReactive(input$data,{
inFile1 <- input$data
if (is.null(inFile1)) {
return(NULL)
} else {
return(read.csv(inFile1$datapath, sep = input$sep1, header = T, stringsAsFactors = F))
}
}) # eventReactive - raw_data
stopwords <- eventReactive(input$stopwords,{ #needed for topic_model
inFile2 <- input$stopwords
if (is.null(inFile2)) {
return(NULL)
} else {
return(read.csv(inFile2$datapath, sep = input$sep2, header = F, stringsAsFactors = F))
}
}) # eventReactive - stopwords
data <- eventReactive(input$date, { #raw_data turns into data
if(!exists(input$data)) return() # if no upload
switch (input$date,
"ydm" = ydm(raw_data()$File.Date),
"mdy" = mdy(raw_data()$File.Date),
"dmy" = dmy(raw_data()$File.Date),
"ydm" = ydm(raw_data()$File.Date)
)
return(raw_data())
}) # reactive - date switch
plot_data <- eventReactive(input$go, {
stopwords <- stopwords()
dats <- data()
topic_model(dats)
return(list(lda_model, dtm, doc_topic_distr,k))
}) # reactive - modeling
output$LDAplot <- renderVis({
plot_data()[[1]]$plot(out.dir = "SOME_DIR", open.browser = FALSE)
readLines("SOME_DIR/lda.json")
})
这是我得到的错误:Listening on http://127.0.0.1:3363
Warning: Error in exists: invalid first argument
[No stack trace available]