这里的新手..。
我正在努力创建一个字云的r闪亮的应用程序。
这是我在戒毒所里的情况:
tabPanel("Word Cloud", sidebarLayout( # Sidebar with a slider and selection inputs sidebarPanel( selectInput("Subcategory", "Choose a Subcategory:", choices = makeup$SubCategory), sliderInput("freq", "Maximum Number of Words:", min = 1, max = 7, value = 5), sliderInput("max", "Minimum Frequency:", min = 1, max = 6000, value = 1000) ), mainPanel( plotOutput("plot") ))
这是我在我的服务器上所拥有的。
shinyServer(输入、输出、会话){ word =反应性({ myCorpus =Corpus(VectorSource( select,SubCategory == >input$==,select=ChemicalName)) myCorpus = tm_map( myCorpus,content_transformer(Tolower) myCorpus = tm_map(myCorpus,removePunctuation) myCorpus= tm_map(myCorpus,removeNumbers) myDTM = TermDocumentMatrix( myCorpus ) m= as.matrix(myDTM) v= sort(rowSums(m),递减=真) data.frame(word=names(v),freq=v)$word }) freq =反应性({ myCorpus =Corpus(子集(化妆,SubCategory == >输入$$子类别,select =ChemicalName))myCorpus=ChemicalName( content_transformer(tolower)) myCorpus = tm_map( myCorpus,removePunctuation) myCorpus= tm_map(myCorpus,removeNumbers) myDTM = TermDocumentMatrix(myCorpus) m= as.matrix(myDTM) v= sort(rowSums(m),递减= TRUE) data.frame(word=names(v),myDTM })输出$plot <- (字数= word,random.order=FALSE,rot.per=0.3,scale=c(4,.5),max.words=15,colors=brewer.pal(8,“Dark2”) })
我不能让我的闪亮的应用程序显示字云..。
我还收到了一个警告信息:
。警告:最大值中的错误:参数的类型(闭包)无效
有什么主意吗?!
谢谢!
发布于 2018-05-08 06:43:22
反应是函数而不是变量。试试这个-应该管用的。
output$plot <- renderPlot({
wordcloud(words = word(),
freq = freq(),
random.order=FALSE, rot.per=0.3,
scale=c(4,.5),max.words=15,
colors=brewer.pal(8,"Dark2"))
})
发布于 2018-05-08 06:56:02
@Bertil男爵对你最紧迫的问题有正确的答案。我想我可以提供一些关于精简应用程序/代码的建议。
shinyServer(function(input, output, session) {
word = reactive({
myCorpus = Corpus(VectorSource(subset(makeup,
SubCategory == > input$Subcategory,
select = ChemicalName)))
myCorpus = tm_map(myCorpus, content_transformer(tolower))
myCorpus = tm_map(myCorpus, removePunctuation)
myCorpus = tm_map(myCorpus, removeNumbers)
myDTM = TermDocumentMatrix(myCorpus)
#m = as.matrix(myDTM) ##this can cause an memory error if your corpus is even moderately sized.
#row_sums from the slam package is much more efficient as it is designed to operate on sparse matrices and TDM/DTMs from the tm package are sparse matrices which are constructed using slam
v = sort(slam::row_sums(myDTM),decreasing = TRUE)
data.frame(word=names(v),freq=v) #Since you've already calculated frequency here there is no need for the freq reactive. We can just access the freq from this data.frame
})
#this is a redundant reprocessing of your corpus (which can be time consuming if it is big.
#freq = reactive({
# myCorpus = Corpus(VectorSource(subset(makeup, SubCategory == > input$Subcategory, select = ChemicalName)))
# myCorpus = tm_map(myCorpus, content_transformer(tolower))
# myCorpus = tm_map(myCorpus, removePunctuation)
# myCorpus = tm_map(myCorpus, removeNumbers)
# myDTM = TermDocumentMatrix(myCorpus)
# m = as.matrix(myDTM)
# v = sort(rowSums(m),decreasing = TRUE)
# data.frame(word=names(v),freq=v)$freq
# })
output$plot <- renderPlot({
wordcloud(words = word()$word,
freq = word()$freq,
random.order=FALSE, rot.per=0.3,
scale=c(4,.5),max.words=15,
colors=brewer.pal(8,"Dark2"))
})
https://stackoverflow.com/questions/50220561
复制