r - 使用 LDAvis 和 R shinyapp 和参数设置进行主题建模可视化
问题描述
我在 R 闪亮的应用程序中使用 LDAvis。
这是代码,它可以正常工作。
# docs is a csv file with a "text" column, e.g.
# docs <- read.csv("docs.csv",sep=",",header=TRUE)
ui <- navbarPage(
title = "NLP app",
tabPanel("Topic Model",icon = icon("group"),
fluidPage(
headerPanel(""),
titlePanel(p(h2("Topic Modelling example",style = "color:#4d3a7d"))),
#sidebarPanel(
wellPanel(tags$style(type="text/css", '#leftPanel { width:200px; float:left;}'), style = "background: lightgrey",
id = "leftPanel",
sliderInput("nTopics", "Number of topics to display", min = 5, max = 50, value = 10, step=5),
sliderInput("nTerms", "#top terms per topic", min = 10, max = 50, value = 20, step=5),
tags$hr(),
actionButton(inputId = "GoButton", label = "Go", icon("refresh"))
),
mainPanel(
tabPanel("Topic Visualisation", hr(),helpText(h2("Please select a topic!")), visOutput('visChart')))
)
)
)
# server
server <- function(input, output, session) {
Topic_Subset <- reactive({
docs <- docs$text
nTopics <- input$nTopics
# topic model using text2vec package
tokens = docs %>%
tolower %>%
word_tokenizer
it = itoken(tokens, progressbar = FALSE)
v = create_vocabulary(it,stopwords=tm::stopwords("en"))
vectorizer = vocab_vectorizer(v)
dtm = create_dtm(it, vectorizer, type = "dgTMatrix")
lda_model = text2vec::LDA$new(n_topics = nTopics, doc_topic_prior = 0.1, topic_word_prior = 0.01)
lda_model$fit_transform(x = dtm, n_iter = 1000,
convergence_tol = 0.001, n_check_convergence = 25,
progressbar = FALSE)
return(lda_model) #
})
output$visChart <- renderVis({
input$GoButton
isolate({
nterms <- input$nTerms
lda_model <- Topic_Subset()
})
lda_model$plot(out.dir = "./results", R = nterms, open.browser = FALSE)
readLines("./results/lda.json")
})
}
shinyApp(ui = ui, server = server)
我想看看是否可以在 visOutput('visChart') 中使用 width = "80%" ,例如 wordcloud2Output("a_name",width = "80%"); 或任何使可视化尺寸更小的替代方法。特别是,当我最小化闪亮的应用程序窗口时,该图不适合页面。我的第二个问题是:如何用另一个数字(如 0.6(不是 1))初始化参数 lambda(请参见下图和黄色高亮部分)?
解决方案
推荐阅读
- elasticsearch - 使用 elasticsearch 作为数据库在 ag-grid 中执行服务器端操作
- java - 防止删除并允许插入和只读功能的集合/数据结构
- android - 迁移到 androidx 后找不到 getActivity() 和几个错误
- ansible - 清单组中的ansible语法错误计数主机
- node.js - 获取 SQL 不同数据 Bookshelf Model
- php - 如何实现基于x分钟到xx分钟车程的地点范围的查询?
- c# - 我正在使用 System.Diagnostics.Process 运行 sqlite 特殊命令,但只有一半的命令被执行
- r - 使字符列哑化,但每行中的类别数不相等
- c# - 时区索引值
- scala - 如何将新列和相应的行特定值添加到火花数据框中?