我正在设计一个 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
我在这里做错了什么?