我试着用这个解决方案来指导我的问题,但没有用,我希望有人能轻易地看到我的错误。
我得到了同样的错误"Error in as.double(y):无法将类型‘闭包’强制到‘double’类型的向量,但是我尝试使用绘制一个TermDocumentMatrix。我的代码如下:
ui.R
library(shiny)
library(shinyIncubator)
shinyUI(navbarPage("Test", id="nav",
tabPanel("Correlation Plot",
progressInit(),
# Sidebar with a slider and selection inputs
sidebarPanel(width = 5,
selectInput("selection", "Choose a reason:",
choices = books),
actionButton("update", "Change"),
hr(),
sliderInput("freq",
"Minimum Frequency:",
min = 1, max = 50, value = 15),
sliderInput("correl",
"Correlation Threshold:",
min = 0, max = 1, value = 0.8)
),
# Show plot
mainPanel(
plotOutput("cplot")
)
)
))global.R
library(tm)
library(wordcloud)
library(memoise)
# The list of valid books
books <<- list("1" = "1", "2"= "2")
# Using "memoise" to automatically cache the results
getTermDoc <- memoise(function(book) {
if (!(book %in% books))
stop("Unknown book")
text = read.table(sprintf("./%s.txt", book),sep="\r",quote="")
myCorpus = Corpus(VectorSource(text))
myCorpus = tm_map(myCorpus, content_transformer(tolower))
myCorpus = tm_map(myCorpus, removePunctuation)
myCorpus = tm_map(myCorpus, removeNumbers)
myCorpus = tm_map(myCorpus, removeWords,stopwords("english"))
myDTM = TermDocumentMatrix(myCorpus)
})server.R
library(shiny)
library(shinyIncubator)
library(tm)
shinyServer(function(input, output, session) {
# Define a reactive expression for the document term matrix
doc <- reactive({
# Change when the "update" button is pressed...
input$update
# ...but not for anything else
isolate({
withProgress(session, {
setProgress(message = "Processing corpus...")
getTermDoc(input$selection)
})
})
})
plot_rep <- repeatable(plot)
#correlation plot
output$cplot <- renderPlot({
plot_rep(doc,
terms = findFreqTerms(doc, lowfreq = 500),
#terms = findFreqTerms(doc, lowfreq = input$freq),
#weighting = TRUE,
corThreshold = 0.975
#corThreshold = input$correl
#nodeAttrs=list(fillcolor=vc)
)
})
})发布于 2014-08-14 02:48:36
当你打电话的时候
doc <- reactive({...})reactive调用实质上是返回一个函数,必须调用该函数才能获得doc的值。所以而不是
plot_rep(doc,
terms = findFreqTerms(doc, lowfreq = 500)使用
plot_rep(doc(),
terms = findFreqTerms(doc()), lowfreq = 500)https://stackoverflow.com/questions/25299176
复制相似问题