【问题标题】:Text highlighting using sentimentr and shiny on flexdashboard in r is throwing error "attempt to apply non-function"在 r 的 flexdashboard 上使用感测器和闪亮突出显示的文本会引发错误“尝试应用非功能”
【发布时间】:2019-08-13 11:50:55
【问题描述】:

我正在设计一个 R FlexDashboard,我在其中使用以下代码上传 CSV 数据:

# "File Upload" button
fileInput("file1", "Load CSV/TSV File:",
          accept = c("text/csv", "text/comma-separated-values, text/plain", 
          ".csv", "text/tab-separated-values", ".tsv") )
# whether 1st row is header?
checkboxInput("header", "Is first row the Header?", TRUE)

然后我使用响应式方法来选择数据集:

# reactive dataset
data_set <- reactive({
   req(input$file1)
   inFile <- input$file1
   data_set <- read.csv(inFile$datapath, header=input$header)
})

这是用于从数据集列“文本”中选择特定行的滑块输入:

# sidebar slider input
sliderInput("disp", "Select Text:", min = 1,  max = 100, value = 20)
actionButton("display","Highlight Sentiments")
hr()

HL1 <- eventReactive(input$display, { data_set()[input$disp, "Text"] })

最后,使用观察输入,我尝试使用sentimentr 包根据情绪(负面或正面)突出显示所选文本:

observeEvent(input$display3, {
    output$HLRes <- renderUI({ 

      require(dplyr)
      require(sentiment)

      HL1() %>% 
        as.character() %>%
        sentiment_by() %>% highlight()
    })
})

当我想从上面显示突出显示的文本时:

htmlOutput("HLRes")

我收到以下错误:

 Error: attempt to apply non-function

我在这里做错了什么?

【问题讨论】:

    标签: r shiny flexdashboard sentimentr


    【解决方案1】:

    我今天遇到了同样的问题,发现了这个:

    https://github.com/trinker/sentimentr/issues/110

    按照建议,添加以下内容使其工作(sentiment_by object

    attr(sb, "averaging.function") &lt;- sentimentr::average_downweighted_zero

    帮我修好了。

    【讨论】:

    • 我想学习一下,使用我上面的代码在浏览器中打开的输出html文件,可以在Flexdashboard box中打开吗?
    猜你喜欢
    • 2019-08-16
    • 1970-01-01
    • 2018-07-14
    • 2021-02-24
    • 2020-08-13
    • 2013-04-27
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多