R - Shiny | Error in cat(list(…), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat'

巧了我就是萌 提交于 2019-12-07 04:39:51

问题


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;

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)
    })
  })

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

lappend <- function(lst, obj) {
  lst[[length(lst)+1]] <- obj
  return(lst)
}

Data Head

The head for my data looks like below

  1. KEY.......SUPPLYCHANNEL......MISCTEXTFEEDBACK
  2. 1234......Goods..............'My experience was great'
  3. 1235......N/A..................'My experience was terrible'
  4. 1236......National...........'I ordered this item'
  5. 1237......Goods..............'I got a refund'

Apologies for the poor formatting above.


回答1:


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().




回答2:


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.




回答3:


The only problem is that you use renderText() but you have multiple lines of output. You can fix this using renderUI() instead




回答4:


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().




回答5:


This error gets thrown when you create a renderText in your server and you fill it with some html tags for instance (ex: h3(...)), instead of a single line of standard text.

Remove the tag and the error might disapear.



来源:https://stackoverflow.com/questions/29041449/r-shiny-error-in-catlist-file-sep-fill-labels-append-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!