首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在闪亮的R中选择

在闪亮的R中选择
EN

Stack Overflow用户
提问于 2016-11-16 03:39:39
回答 1查看 273关注 0票数 1

我不能获得select input的值,我需要生成一个单词云,但是云的内容将取决于所选的选项。

应用程序正在无限加载。请帮帮我。

UI.R

代码语言:javascript
复制
fluidPage(
# Application title
titlePanel("Word Cloud"),

sidebarLayout(
# Sidebar with a slider and selection inputs
sidebarPanel(
  selectInput("selection", "Choose a book:",
              choices = c(coletor1,coletor2),
        selected = coletor1),
  actionButton("update", "Change"),
  hr(),
  sliderInput("freq",
              "Minimum Frequency:",
              min = 1,  max = 1000, value = 1),
  sliderInput("max",
              "Maximum Number of Words:",
              min = 1,  max = 100,  value = 100)
),

# Show Word Cloud
mainPanel(
 tabsetPanel(type = "tabs", 
     tabPanel("Plot", plotOutput("plot"))

)

)))

Server.R

代码语言:javascript
复制
function(input, output, session) {

# Define a reactive expression for the document term matrix
terms <- reactive({
# Change when the "update" button is pressed...
input$update
# ...but not for anything else
isolate({
  withProgress({
    setProgress(message = "Processing corpus...")
    getTermMatrix(input$selection)
  })
})
})

# Make the wordcloud drawing predictable during a session
wordcloud_rep <- repeatable(wordcloud)

output$plot <- renderPlot({
v <- terms()
wordcloud_rep(names(v), v, scale=c(4,0.5),
              min.freq = input$freq, max.words=input$max,
              colors=brewer.pal(8, "Dark2"))
})
}

Global.R

代码语言:javascript
复制
library(tm)
library(wordcloud)
library(memoise)

library(RPostgreSQL)
con <- dbConnect(PostgreSQL(), user="postgres",      password="123456",dbname="postgres")
coletor1=dbGetQuery(con,"SELECT REPLACE(aux_coletprinc,' ','')          aux_coletprinc  from jabot.detacesso2 where aux_coletprinc ilike '%forz%a%'
")
coletor2=dbGetQuery(con,"SELECT REPLACE(aux_coletprinc,' ','')   aux_coletprinc  from jabot.detacesso2 where aux_coletprinc ilike '%vian%a%'
")

dbDisconnect(con)
list<-c(coletor1,coletor2) 

# Using "memoise" to automatically cache the results
getTermMatrix <- memoise(function(list) {

text <- list

myCorpus = Corpus(VectorSource(text))
myCorpus = tm_map(myCorpus, content_transformer(tolower))

myDTM = TermDocumentMatrix(myCorpus,
          control = list(minWordLength = 1))

m = as.matrix(myDTM)

sort(rowSums(m), decreasing = TRUE)
})
EN

回答 1

Stack Overflow用户

发布于 2016-11-16 04:30:26

global.Rserver.Rui.R之前运行。正因为如此,现在还没有input$selection

您只需在global.R中定义getTermMatrix函数。不需要定义a,也不需要定义要读取的text

您可以在server.R中执行这两项操作,因为input列表已经存在。尽管更仔细地研究一下您的getTermMatrix()函数,但book参数从未使用过。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40618309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档