如何将多个文件上传到R中的单个变量

时间:2018-04-26 11:05:00

标签: r shiny text-mining

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

应用功能的简短说明:

  1. 提供Wordcloud
  2. 提供Wordcorrelation(输入$ v)
  3. Sentimentanalysis
  4. 最常用的词语
  5. 服务器代码:

    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”。

    提前致谢:)

0 个答案:

没有答案
相关问题