gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:29:48 25 4
gpt4 key购买 nike

我试图编写一个Shiny应用程序,并且需要先操纵我的数据,然后才能开始对其进行可视化。我有三个输入来操纵数据。
1. channel
2.排除一个词
3.找到所有带有该词的评论

我能够完成前两个,但是在使用grep()函数查找包含某个单词的所有行时,我遇到了以下错误
“cat(list(...),file,sep,fill,labels,append)中的错误:
参数1(类型“列表”)不能由“猫”处理”

有人知道如何处理吗?或究竟是什么原因造成的?我认为是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')
)

)
)

服务器
    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)
}

数据头

我的数据的头部如下所示
  • KEY ....... SUPPLYCHANNEL ...... MISCTEXTFEEDBACK
  • 1234 ......商品..............'我的经历很棒'
  • 1235 ...不适用.........'我的经历很糟糕'
  • 1236 ......国民............'我已订购此商品'
  • 1237 ......商品..............'我已退款'

  • 抱歉,上面的格式不正确。

    最佳答案

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

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

    关于R- Shiny | cat(list(...),file,sep,fill,labels,append)中的错误: argument 1 (type 'list' ) cannot be handled by 'cat' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29041449/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com