首页 > 解决方案 > 如何将多个文件上传到R中的单个变量

问题描述

所以我有以下代码。有用。事情是我希望能够读取多个文件以对整个部分而不是 1 个文档进行分析。

应用功能的简短说明:

  1. 提供文字云
  2. 提供 Wordcorrelation (input$v)
  3. 情绪分析
  4. 最常用的词

服务器代码:

server <- function(input, output) {
  output$plot <- renderPlot({
    file1 <- input$file1
    file2 <- input$file2
if (is.null(file1) && is.null(file2))
  return(NULL)

if (!is.null(file1)) {
  in2 <- pdf_text(file1$datapath)
}
if (!is.null(file2)) {
  in2 <- readLines(file2$datapath)
}

界面代码

ui <- shinyUI(fluidPage(
titlePanel("Textmining Tool v0.1"),
sidebarLayout(
sidebarPanel(
  fileInput('file1', 'Choose PDF',
            accept = c('text/pdf',
                       '.pdf')),
  fileInput(
    'file2',
    'Choose TXT,CSV', multiple = T,
    accept = c(
      'text/csv',
      'text/comma-separated-values',
      'text/tab-separated-values',
      'text/plain',
      '.csv',
      '.tsv'
    )
  ),

  fileInput(
    'pos',
    'Choose pos',
    accept = c(
      'text/csv',
      'text/comma-separated-values',
      'text/tab-separated-values',
      'text/plain',
      '.csv',
      '.tsv'
    )
  ),

  fileInput(
    'neg',
    'Choose neg',
    accept = c(
      'text/csv',
      'text/comma-separated-values',
      'text/tab-separated-values',
      'text/plain',
      '.csv',
      '.tsv'
    )
  ),
  sliderInput(
    "freq",
    "Minimum Frequency:",
    min = 1,
    max = 50,
    value = 15
  ),
  sliderInput(
    "max",
    "Maximum Number of Words:",
    min = 1,
    max = 300,
    value = 100
  ),

  textInput("v", "Input correlation word", "")
 ),

 mainPanel(
  tabsetPanel(
    type = "pills",
    tabPanel("Wordcloud", plotOutput("plot")),
    tabPanel("Wordcorrelation",DT::dataTableOutput("table")),
    tabPanel("Sentimentanalysys", textOutput("sent")),
    tabPanel("Most Frequent", DT::dataTableOutput("2"))
     )
    )
  )
))

所以我感兴趣的是:如何将多个文件上传转换为单个文件变量,如“in2”。

提前致谢:)

标签: rshinytext-mining

解决方案


推荐阅读