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



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

我能够完成前两个,但是当涉及到使用 grep() 函数查找包含某个单词的所有行时,我遇到了以下错误"cat(list(...),文件,sep,填充,标签,附加中的错误: 参数 1(类型'列表')不能由'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')
)

))

服务器.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 <- function(lst, obj) {
  lst[[length(lst)+1]] <- obj
  return(lst)
}

数据头

我的数据头如下所示

  1. .KEY。。。。。。。供应渠道...杂项文本反馈
  2. 1234......货物.............."我的经历很棒"
  3. 1235......N/A............"我的经历太糟糕了"
  4. 1236......国家..........'我订购了这个项目'
  5. 1237......货物.............."我得到了退款"

对于上面的格式不佳表示歉意。

根据

我的经验,错误argument 1 (type 'list') cannot be handled by 'cat'来自将列表传递给渲染...() 命令。我的猜测是,您正在将列表传递给server.r底部的output$table <- renderText({

此外,我看到的所有示例renderText()只呈现一行文本。如果要渲染多行,请尝试 renderUI() ,它也可以处理某些类型的列表,例如 Shiny 自己的tagList()

仅用于注册(可能对某人有用)。我有同样的问题,对我来说,解决方案是将renderText更改为renderPrint.

但就我而言,我试图对lm()进行总结.

我今天遇到了这个错误。

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

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

唯一的问题是你使用renderText()但你有多行输出。您可以使用renderUI()来解决此问题

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

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

最新更新