2017-11-25 1 views
1

Ich möchte Shiny verwenden, um meine Text-Mining-AnalyseprozessR Shiny: Kann nicht Funktion in verschiedenen TabPanel verwenden

Aber ich bin verwirrt Demo dass glänzend nicht fertig Funktion (oder Daten verwenden können, Datenrahmen, Matrix. ..etc) in verschiedenen tabPanel.

Es ist wirklich ein großes Problem für mich, den nächsten Analyseprozess aufzubauen.

Gibt es eine Möglichkeit, dieses Problem zu lösen?

Es die Fehlermeldung zeigt: enter image description here

hier ist mein Test-Analyse-Datei Download-Link: https://drive.google.com/uc?export=download&id=1A9BtTplgy42etAh42YwLiZJAwl_RSNF-

ui.r

library(shiny) 

# Define UI for data upload app ---- 
navbarPage( 
    title = 'Patent Analysis System',   
    #Table1----------------------------------------------------   
    tabPanel("Upload Patent File", fluidPage(

    # App title ---- 
    titlePanel("Uploading Files"), 

    # Sidebar layout with input and output definitions ---- 
    sidebarLayout(
     # Sidebar panel for inputs ---- 
     sidebarPanel(

     # Input: Select a Patent file ---- 
     fileInput("patent_file", "Choose Patent File", 
        multiple = TRUE, 
        accept = c("text/csv", 
          "text/comma-separated-values,text/plain", 
          "csv")), 

     #submit button 
     submitButton("Update View", icon("refresh")) 

    ), 

     # Main panel for displaying outputs ---- 
     mainPanel(
     tabsetPanel(
      tabPanel("Load Files",tableOutput("contents"),id="load_files"), 

      tabPanel("Patents Preprocess",fluidPage(
      sidebarPanel(
       selectizeInput("choose_patent", "Choose Patent", 
          choices = 1:10 ,selected = 1), 
       submitButton("Update", icon("refresh")) 
      ) 
     ), 
      verbatimTextOutput("patent_pre_process")), 
      tabPanel("Convert martix(TF)", 
        tableOutput("mat_tf"), id="matrix_tf") 
     ) 
    ) 
    ) 
)), 
    tabPanel('Process2 ', DT::dataTableOutput('ex5')) 
) 

server.r

library(ontologyIndex) 
library(magrittr) 
library(tidyr) #separate_rows 
library(quanteda) #tolower 
library(SnowballC) #wordstem 
library(gtools) 
library(tm) 
library(wordcloud) 
library(textreg) 

server <- function(input, output, session) { 
    options(shiny.maxRequestSize = 30*1024^2) 
    #1. File load------------------------------------------------------------------------ 
    output$contents <- renderTable({ 
    req(input$patent_file) 
    patent_df <- read.csv(input$patent_file$datapath) 
    patent_df 

    }) 

    #2. Patent preprocess---------------------------------------------------------------- 
    output$patent_pre_process <- renderPrint({ 
    req(input$patent_file) 
    df_cmp <- read.csv(input$patent_file$datapath, stringsAsFactors = F) 

    #Build Corpus (Title)-------------------------------------------------------------- 
    df_title <- data.frame(Title=df_cmp$English.title) 
    corpus_title <- Corpus(DataframeSource(df_title)) 

    #Pre-processing and tranforming the Corpus 
    corpus_tm_title <- tm_map(corpus_title, content_transformer(tolower)) %>% 
     tm_map(removeNumbers) 

    #Build Corpus (Abstract)------------------------------------------------------------ 
    df_abstract <- data.frame(abstract=df_cmp$English.abstract) 
    corpus_abstract <- Corpus(DataframeSource(df_abstract)) 

    #Pre-processing and tranforming the Corpus 
    corpus_tm_abstract <- tm_map(corpus_abstract, content_transformer(tolower)) %>% 
     tm_map(removeNumbers) %>% 
     tm_map(stripWhitespace) 

    #Patent result output--------------------------------------------------------------- 
    pat_num <- 1:length(df_cmp$Publication.numbers) 
    updateSelectInput(session, "choose_patent", "Choose Patent :", choices = pat_num) 
    choose_pat_num <- as.integer(input$choose_patent) 

    list(Title=content(corpus_tm_title[[choose_pat_num]]), 
     Abstract= content(corpus_tm_abstract[[choose_pat_num]])) 

    }) 

    #3. Matix----------------------------------------------------------------------------- 

    output$mat_tf <- renderTable({ 

    #Title 
    title_convert <- convert.tm.to.character(corpus_tm_title) 
    mat_title <- dfm(title_convert, what = "word", remove_punct = FALSE, 
        ngrams = 1:3, concatenator = " ") %>% 
     as.matrix()*3 

    #Combine title/ads/claim dtm-------------------------------------------------------- 
    tf_mat <- cbind(mat_title, mat_abstract) 
    tf_mat 
    }) 
} 

Antwort

0

Ihr Problem besteht darin, dass Sie alle Berechnungen in Renderfunktionen platziert haben. Dies sind Designs, um die Ausgabe an eine einzige Quelle und nichts anderes zu rendern. Sie möchten wirklich alle Berechnungen in reaktiven Ausdrücken machen und Ketten damit bauen. Im Folgenden habe ich Ihren Code (ohne Tests) so umformuliert, dass er meiner Meinung nach gut funktionieren sollte.

library(ontologyIndex) 
library(magrittr) 
library(tidyr) #separate_rows 
library(quanteda) #tolower 
library(SnowballC) #wordstem 
library(gtools) 
library(tm) 
library(wordcloud) 
library(textreg) 

server <- function(input, output, session) { 
    options(shiny.maxRequestSize = 30*1024^2) 
    #1. File load------------------------------------------------------------------------ 
    patent_df <- reactive({ 
    read.csv(input$patent_file$datapath, stringsAsFactors = F) 
    }) 

    output$contents <- renderTable({ 
    req(input$patent_file) 
    patent_df() 

    }) 

    #2. Patent preprocess---------------------------------------------------------------- 
    preProcess <- reactive({ 
    req(input$patent_file) 
    df_cmp <- patent_df() 

    #Build Corpus (Title)-------------------------------------------------------------- 
    df_title <- data.frame(Title=df_cmp$English.title) 
    corpus_title <- Corpus(DataframeSource(df_title)) 

    #Pre-processing and tranforming the Corpus 
    corpus_tm_title <- tm_map(corpus_title, content_transformer(tolower)) %>% 
     tm_map(removeNumbers) 

    corpus_tm_title 
    }) 

    dtaCorpus <- reactive({ 
    #Build Corpus (Abstract)------------------------------------------------------------ 
    df_cmp <- patent_df() 
    corpus_tm_title <- preProcess() 
    df_abstract <- data.frame(abstract=df_cmp$English.abstract) 
    corpus_abstract <- Corpus(DataframeSource(df_abstract)) 

    #Pre-processing and tranforming the Corpus 
    corpus_tm_abstract <- tm_map(corpus_abstract, content_transformer(tolower)) %>% 
     tm_map(removeNumbers) %>% 
     tm_map(stripWhitespace) 

    #Patent result output--------------------------------------------------------------- 
    pat_num <- 1:length(df_cmp$Publication.numbers) 
    updateSelectInput(session, "choose_patent", "Choose Patent :", choices = pat_num) 
    choose_pat_num <- as.integer(input$choose_patent) 

    list(Title=content(corpus_tm_title[[choose_pat_num]]), 
     Abstract= content(corpus_tm_abstract[[choose_pat_num]])) 

    }) 
    output$patent_pre_process <- renderPrint({ 
    dtaCorpus() 
    }) 

    #3. Matix----------------------------------------------------------------------------- 

    output$mat_tf <- renderTable({ 

    corpus_tm_title <- preProcess() 
    #Title 
    title_convert <- convert.tm.to.character(corpus_tm_title) 
    mat_title <- dfm(title_convert, what = "word", remove_punct = FALSE, 
        ngrams = 1:3, concatenator = " ") %>% 
     as.matrix()*3 

    #Combine title/ads/claim dtm-------------------------------------------------------- 
    tf_mat <- cbind(mat_title, mat_abstract) 
    tf_mat 
    }) 
} 

hoffe, das hilft

+0

ich es irgendein Problem mit dem Code ich es näher an diesem Abend aussehen wird, wenn ich ein bisschen mehr Zeit –

+0

Dank haben. Ich habe versucht reactive() für wiederverwendete Objekte zu verwenden. – Eva

Verwandte Themen