我正在尝试在Shiny中进行一些文本分析。首先,我通过ui.R文件中的fileinput()选项上传一些文本文件。 Ui.R的相关片段如下所示(FileInput)
Ui.R文件
sidebarPanel(
selectInput("langsel","Choose Your Language:",choices=list("English"="eng","Hindi"="hind")), # This will go as drop down in the app.
br(), # A break in the panel
uiOutput("movie_list"), # This list of movies will come from renderUI of server based on selection of language
br(),
fileInput("movtext","Upload the movie reviews"), # The fileinput() function is used to get the fileupload option
helpText("Default File Size is 5 MB") # A help text
), # End of sidebarpanel
通过ui.R上传文本文档后,我通过" server.r"中的反应函数读取它。文件。正确读取文件并正确显示。以下是" server.R"的片段。文件。
server.r
textanalysis <- reactive({
text1 <- input$movtext # Stores the uploaded file in the variable text1. The uploaded file is a text file
movtxt1 <- scan(text1$datapath,character(0),sep=".") # Reading the text file using the "scan" function
但是,当我尝试使用length()函数找到文本字符串的长度时。它将错误抛出为
标记$ name中的错误:$ operator对原子向量无效
我知道&#34; movtxt1&#34;中有多个字符串。变量,因为当我使用movtxt1 [1]或任何其他值对其进行子集时,它会显示相关文本。我试图找到作为此文本文件的一部分的字符串数,我无法使用length()函数。请求你帮助解决问题。