R - 闪亮 | cat(list(...), file, sep, fill, labels, append) 中的错误:“cat”无法处理参数 1(类型“list”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29041449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:07:24  来源:igfitidea点击:

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

rlistshinyshiny-server

提问by Jacob Johnston

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

我正在尝试编写一个 Shiny 应用程序,在开始可视化之前需要先操作我的数据。我有三个输入来操作数据。1. 频道 2. 排除一个词 3. 找到所有包含这个词的评论

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'"

我能够完成前两个,但是在使用 grep() 函数查找包含某个单词的所有行时,我遇到了以下错误“cat(list(...), file, sep、fill、labels、append):参数 1(类型 'list')不能由 '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

任何人都知道如何处理这个问题?或者究竟是什么原因造成的?我认为是 grep() 函数使用列表来告诉我哪些行包含该单词。但我不确定是否有解决办法,并且在这方面花了很多时间

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'
  1. 关键…………供应渠道……杂项文本反馈
  2. 1234......商品......'我的经历很棒'
  3. 1235......不适用............'我的经历很糟糕'
  4. 1236......National.......'我订购了这个项目'
  5. 1237......货物......'我得到了退款'

Apologies for the poor formatting above.

对上述格式不佳表示歉意。

回答by 3D0G

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.

根据我的经验,错误argument 1 (type 'list') cannot be handled by 'cat'来自将列表传递给 render...() 命令。我的猜测是您将列表传递到output$table <- renderText({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().

此外,我见过的所有示例renderText()都只呈现一行文本。如果你想渲染多条线,试试renderUI(),它也可以处理一些类型的列表,比如 Shiny 自己的tagList().

回答by Dave

I had exactly this error today.

我今天正好有这个错误。

Solution: there was a })missing at the end of an output$something statement.

解决方案:})output$something 语句的末尾缺少一个。

It didn't show up as an error when compiling, so it was hard to spot.

它在编译时没有显示为错误,因此很难发现。

回答by M455y

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

唯一的问题是您使用renderText()但您有多行输出。您可以renderUI()改用

回答by agenis

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

当您renderText在服务器中创建 a并使用一些html标记(例如:)h3(...)而不是一行标准文本填充它时,会引发此错误。

Remove the tag and the error might disapear.

删除标签,错误可能会消失。

回答by Cro-Magnon

Just for register (Maybe useful for someone). I had the same problem, for me the solution was to change renderTextto renderPrint.

仅用于注册(可能对某人有用)。我遇到了同样的问题,对我来说,解决方案是更改renderTextrenderPrint.

But in my case I was trying to make a summary of a lm().

但就我而言,我试图对lm().