我正在尝试构建一个闪亮的应用程序,该应用程序发生了很多事情,单击“执行”按钮,然后加载了数据。加载数据后,应使用单词出现的最小和最大次数来更新滑动条。 当在删除输入文本框中输入单词并单击按钮do时,然后删除该单词作为语料库,对于查找和替换操作也有类似的操作,当发生这种情况时,应更新图形以显示这些更改
library(shiny)
library(plyr)
library(sp)
library(stringr)
library(tidyr)
library(tidyverse)
library(tm)
library(ggplot2)
library("stringi")
library(plyr)
library(dplyr) #Data manipulation (also included in the tidyverse package)
ui <- fluidPage(
fluidRow(
column( 4, titlePanel("Twitter Analytics")),
column( 3),
column( 4,
textInput("searchstring",
label = "",
value = "")),
column(1,
br(),
actionButton("action", "go"))
),
fluidRow(
column( 12, tabsetPanel(
tabPanel("one",
fluidRow(
column(3, textInput("removeString", label = "remove", value = ""), actionButton("remove", "do"),
textInput("find", label = "find", value = ""),textInput("rep", label = "replace", value = ""),actionButton("replace", "act"),
checkboxGroupInput("checkGroup", "select plots",
choices <- c("Histogram", "Wordcloud", "network")),
sliderInput("topTerms",
label = "top (n) terms",
min = 0, max = 25, value = 0) ),
column(9,fluidRow(column(12,plotOutput("ttext") )),
fluidRow(column(12,wordcloud2Output("wc2"))))
)
),
tabPanel("two"),
tabPanel("three")
)
)
)
)
server <- function(input, output) {
values <- reactiveValues(go = 0, do = 0, act = 0 )
observeEvent(input$action, {
values$go <- 1
values$do <- 0
values$act <- 0
})
observeEvent(input$remove, {
values$go <- 0
values$do <- 1
values$act <- 0
})
observeEvent(input$replace, {
values$go <- 0
values$do <- 0
values$act <- 1
})
#tweet <- eventReactive(input$action,{
tweet <-renderUI({
if(values$go){
num <- c(1,2,3,4,50)
text <- c("this is love love something", "this is not hate hate hate something", "@something islove rethched this not", " Shiny is love confusing me", "this is hate also somthing difficult")
letter<- c("a", "b", "c", "D", "e")
tweetdf <- data.frame(num, text, letter)
tweetdf$text <- tolower(tweetdf$text)
# tweetdf @UserName
tweetdf$text <- gsub("@\\w+", "", tweetdf$text)
#remove punctuation
tweetdf$text <- gsub("[[:punct:]]", "", tweetdf$text)
#remove links
tweetdf$text <- gsub("http\\w+", "", tweetdf$text)
# Remove tabs
tweetdf$text <- gsub("[ |\t]{2,}", "", tweetdf$text)
# Remove blank spaces at the beginning
tweetdf$text <- gsub("^ ", "", tweetdf$text)
# Remove blank spaces at the end
corpus <- iconv(tweetdf$text, to = "ASCII")
corpus <- Corpus(VectorSource(corpus))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
cleanset <- tm_map(corpus, removeWords, stopwords('english'))}
if(values$do){
cleanset <- tweet()
cleanset <- tm_map(corpus, removeWords, input$removeString)
}
if(values$act){
cleanset <- tweet()
cleanset <- tm_map(cleanset, gsub,
pattern = input$find,
replacement = input$rep)
}
else
{return()}
})
output$ttext <- renderPlot({
cleanset <-tweet()
tdm <- TermDocumentMatrix(cleanset)
tdm <- as.matrix(tdm)
w <- rowSums(tdm)
library(RColorBrewer)
barplot(w)
})
output$wc2 <- renderWordcloud2({
library(wordcloud2)
cleanset <-tweet()
tdm <- TermDocumentMatrix(cleanset)
tdm <- as.matrix(tdm)
w <- rowSums(tdm)
w <- data.frame(names(w), w)
colnames(w) <- c('word', 'freq')
wordcloud2(w,
color = 'random-dark',
size = 0.7,
shape = 'circle',
rotateRatio = 0.5,
minSize = 1)
})
}
shinyApp(ui, server)
该代码代表了我正在尝试做的事情,但是我不知道从这里去哪里,
我收到以下错误消息:
没有适用于“ TermDocumentMatrix”的适用于“ NULL”类对象的方法