Jac*_*ton 5 r list shiny shiny-server
我正在尝试编写一个Shiny应用程序,并且需要先操纵我的数据,然后才能开始对其进行可视化。我有三个输入来操纵数据。1.频道2.排除单词3.在其中找到所有与此单词相关的评论
我能够完成前两个,但是在使用grep()函数查找包含某个单词的所有行时,我遇到了以下错误“ cat(list(...),file,... sep,fill,labels,append):参数1(类型“ list”)不能由“ cat”处理”
有人知道如何处理吗?或究竟是什么原因造成的?我认为正是grep()函数使用列表来告诉我哪些行包含该单词。但是我不确定是否可以解决这个问题,并且已经花了很多时间在这上面
请在下面找到我的两个代码段;
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')
)
Run Code Online (Sandbox Code Playgroud)
))
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)
})
})
Run Code Online (Sandbox Code Playgroud)
感谢您提供的任何帮助或对当前代码的评论。我还提供了一个函数,该函数用于将单词追加到下面列出的列表中
lappend <- function(lst, obj) {
lst[[length(lst)+1]] <- obj
return(lst)
}
Run Code Online (Sandbox Code Playgroud)
我的数据的头部如下所示
抱歉,上面的格式不正确。
3D0*_*D0G 12
根据我的经验,错误argument 1 (type 'list') cannot be handled by 'cat'来自将列表传递给 render...() 命令。我的猜测是您将列表传递到output$table <- renderText({server.r 的底部。
此外,我见过的所有示例renderText()都只呈现一行文本。如果你想渲染多条线,试试renderUI(),它也可以处理一些类型的列表,比如 Shiny 自己的tagList().