1

I am creating Shiny App and the purpose is to input text file and using udpipe library need to create wordcloud, annoate etc...

I am getting "inherits(x, "character") is not TRUE" when running the app. The problem comes from "Annotate" Tab as i am trying to return datatable from Server.R file

ui.R code:

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'))

              )


)

server.R code

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)
    }
  )


  })

I am trying to return data table in output$Annotate variable. But its not working properly.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

Replace your udpipe_annotate line of code to the following.

txt <- as.character(Dataset())
udpipe_annotate(ud_dutch, x = txt, doc_id = seq_along(txt))

This will avoid that you pass NULL to udpipe_annotate if no text data is loaded yet in your shiny app

  • Thanks for feedback. I have modified the code as above. But now i am getting error as "Warning in read_connlu(x, is_udpipe_annotation = TRUE) : No parsed data in x$conllu, returning default empty data.frame. Error message at x$error indicates".... – Balaji Venky May 28 '18 at 16:28
  • It's not an error, just a warning indicating you don't send text data to annotate. If there is no data to annotate, udpipe returns the default data frame with zero rows. –  May 28 '18 at 18:47
  • Yes, i have fixed that issue. But i am once again facing new issue "Error in as.vector: cannot coerce type 'environment' to vector of type 'character' " if i use the code "txt <- as.character(Dataset())" as suggested by you. – Balaji Venky May 29 '18 at 01:02
  • It probably should have been txt <- as.character(Dataset()) –  May 29 '18 at 10:59
  • Is there any other way to avoid this issue ? – Balaji Venky May 29 '18 at 15:54