I am trying to write a Shiny app and need to first manipulate my data before I begin visualizing it. I have three inputs to manipulate the data. 1. Channel 2. Exclude a word 3. Find all comments with this word in it
I am able to accomplish the first two but when it comes to making using the grep() function to find all rows that contain a certain word I am running into the following error "Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat'"
Anyone have an idea of how to handle this? Or what exactly is causing it? I think it is the grep() function that is using a list to tell me what rows contain the word. But I am not sure of a work around and have spend to much time on this as is
Please find my two snippets of code below;
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')
)
) )
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)
})
})
Any help you can give or comments on my current code is greatly appreciated. I also have sourced a function I used to append words to a list which is listed below
lappend <- function(lst, obj) {
lst[[length(lst)+1]] <- obj
return(lst)
}
The head for my data looks like below
Apologies for the poor formatting above.
In my experience the error argument 1 (type 'list') cannot be handled by 'cat'
comes from passing a list to a render...() command. My guess is that you're passing a list to the output$table <- renderText({
at the bottom of server.r.
In addition, all the examples I've seen of renderText()
just render a single line of text. If you want to render multiple lines, try renderUI()
, which can also handle some types of lists, such as Shiny's own tagList()
.
Just for register (Maybe useful for someone). I had the same problem, for me the solution was to change renderText
to renderPrint
.
But in my case I was trying to make a summary of a lm()
.
I had exactly this error today.
Solution: there was a })
missing at the end of an output$something statement.
It didn't show up as an error when compiling, so it was hard to spot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With