【发布时间】:2014-08-14 10:48:36
【问题描述】:
我尝试使用this solution 作为我的问题的指南,但无济于事,希望有人能轻松看到我的错误。
我遇到了相同的错误“as.double(y) 中的错误:无法将'closure' 类型强制转换为'double' 类型的向量”,但我正在尝试@ 987654322@ 使用 Shiny。我的代码如下:
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")
)
)
))
全球.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)
})
服务器.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)
)
})
})
【问题讨论】: