我正在尝试编写一个闪亮的应用程序,并且需要先操作我的数据,然后才能开始可视化它。我有三个输入来操纵数据。
1. 渠道
2. 排除某个词
3. 查找所有含有该词的评论
我能够完成前两个任务,但是当使用 grep() 函数查找包含某个单词的所有行时,我遇到了以下错误
“cat(列表(...)、文件、sep、填充、标签、附加)中的错误:
参数 1(类型“list”)无法由“cat”处理”
有人知道如何处理这个问题吗?或者到底是什么原因造成的?我认为 grep() 函数使用列表来告诉我哪些行包含该单词。但我不确定是否有解决方法,并且已经在这方面花费了很多时间
请在下面找到我的两段代码;
UI.r
fluidPage(
titlePanel("Groupon Word Cloud"),
sidebarLayout(
sidebarPanel(
selectInput( inputId = "selection",
label = "Choose a Supply Channel",
choices = c('All',
'G1',
'Getaways',
'Goods',
'Live',
'National',
'N/A',
'MM'),
selected = 'All'),
hr(),
textInput( inputId = "exclude",
label = "Exclude a word"),
textInput( inputId = "drill",
label = "Drill down into a word"),
submitButton( text = "Update"),
hr(),
dateRangeInput( inputId = "date",
label = "Date Range",
start = "2015-02-01",
end = NULL ,
min = '2015-02-01',
max = NULL,
format = "yyyy-mm-dd",
startview = 'month',
weekstart = 0,
language = "en",
separator = "to"),
sliderInput( inputId = "freq",
label ="Minimum Frequency:",
min = 1,
max = 50,
value = 15),
sliderInput( inputId = "max",
label = "Maximum Number of Words:",
min = 1,
max = 300,
value = 100)),
# Show Word Cloud
mainPanel(
tableOutput('table')
)
)
)
server.r
library(shiny)
source('data/lappend.r')
#Load and manipulate data on App opening
survey_data <- read.delim(file = "data/Survey_Monkey_3_1_2015.txt"
, header = TRUE
, sep = "|"
, quote = ""
, stringsAsFactors = FALSE)
survey_data <- subset(survey_data, survey_data$Misc_Text_Feedback != '?')
survey_data <- survey_data[,c(2,6)]
stopWords <- read.csv (file = 'data/stop_words.csv')
stopWords <- as.character(stopWords[,2])
shinyServer(
function(input, output) {
#Data subset based on Supply Channel Selection
data <- reactive({
if (input$selection == 'All') {
if(input$drill==""){
survey_data
} else {
drill <- survey_data
drill <- grep(input$drill, drill$Misc_Text_Feedback, value = TRUE)
}
} else {
if(input$drill==""){
subset(survey_data, survey_data$Supply_Channel == input$selection )
} else {
drill <- subset(survey_data, survey_data$Supply_Channel == input$selection)
drill <- grep(input$drill, drill$Misc_Text_Feedback)
}
}
})
stops <- reactive({
stopWords <- lappend(stopWords, input$exclude)
return(stopWords)
})
#Table
output$table <- renderText({
data <- data()
head(data, n = 300)
})
})
非常感谢您提供的任何帮助或对我当前代码的评论。我还提供了一个用于将单词附加到下面列出的列表的函数
Lappend
lappend <- function(lst, obj) {
lst[[length(lst)+1]] <- obj
return(lst)
}
数据头
我的数据的头部如下所示
- 关键......供应渠道......杂项文本反馈
- 1234……好东西…………‘我的经历很棒’
- 第1235章……不适用……‘我的经历很糟糕’
- 1236……全国……‘我订购了这个商品’
- 1237……货…………‘我退款了’
对上面格式不当表示歉意。