r - 在 R 编程 Shiny App 中,inherits(x, "character") 不是 TRUE
问题描述
我正在创建 Shiny App,目的是输入文本文件并使用 udpipe 库需要创建 wordcloud、annoate 等...
运行应用程序时,我收到“inherits(x, "character") is not TRUE"。问题来自“注释”选项卡,因为我试图从 Server.R 文件返回数据表
ui.R 代码:
shinyUI(
fluidPage(
##today's date
dateInput("date6", "Date:",
startview = "decade"),
##current time
h2(textOutput("CurrentTime")),
# Application title
titlePanel("UDPipe Text Analysis"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
# Input: for uploading a file ----
fileInput("file1", "Choose Text File"),
# Horizontal line ----
tags$hr(),
##checkbox input
checkboxGroupInput("upos",label = h4("Parts Of Speech to Show:"),
c("Adjective" = "ADJ",
"Propernoun" = "PROPN",
"Adverb" = "ADV",
"Noun" = "NOUN",
"Verb"= "VERB"),
selected = c("ADJ","NOUN","VERB"),
width = '100%'
#choiceNames =
# list(icon("Adjective"), icon("Adverb")),
#choiceValues =
#list("ADJ", "ADV")
)),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Overview",h4(p("Who deveoped this App")),
p("This app supports only text files. ", align = "justify"),
h4("Pupropse of this app"),
h4("what precaution to take")
),
tabPanel("Annotate",dataTableOutput('Annotate'))
)
)
服务器.R代码
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
Dataset <- reactive({
if (is.null(input$file)) { return(NULL) } else
{
Data <- readlines(input$file1)
Data = str_replace_all(Data, "<.*?>", "")
return(Data)
}
})
output$Annotate <- renderDataTable(
{
english_model = udpipe_load_model("./english-ud-2.0-170801.udpipe")
x <- udpipe_annotate(english_model, x = Dataset)
return(x)
}
)
})
我正在尝试在 output$Annotate 变量中返回数据表。但它不能正常工作。
解决方案
将您udpipe_annotate
的代码行替换为以下内容。
txt <- as.character(Dataset())
udpipe_annotate(ud_dutch, x = txt, doc_id = seq_along(txt))
如果您的闪亮应用程序中尚未加载文本数据,这将避免您传递NULL
给udpipe_annotate
推荐阅读
- swift - 将 EKRecurrenceRule 添加到提醒不起作用(创建重复事件问题)
- angular - 如何检测我的formGroup中的哪些输入字段处于模糊状态,Angular 9
- clang - QtCreator 注解编译器找不到 stdbool.h
- go - 如何拆分 .txt 文件的行并将它们添加到 Go 中的切片中?
- scala - 如何从字符串scala中提取文件扩展名
- swift - 具有多个实体的单元测试核心数据
- go - 从接口通道流到类型切片
- reactjs - ag-grid 选择所有组子项
- reactjs - 在 materia ui ToolTip 中使用悬停并单击会导致关闭工具提示时出现问题
- swift - 根据设备更改字体大小