I can not get the value of select input, I need to generate a cloud of words, but the content of the cloud will depend on the selected option.
The application is loading infinitely. Help me please.
UI.R
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
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
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)
})
global.R
runs before server.R
and ui.R
. Because of this, there is no input$selection
yet.
You just have to define the getTermMatrix
function in global.R
. There is no need to define a
nor the text
that is going to be read.
You can do both in server.R
, where the input
list already exists. Altough, take a better look into your getTermMatrix()
function, the book
argument is never used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.