inherits(x, "character") is not TRUE in R programming Shiny App

1.6k views Asked by At

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.

1

There are 1 answers

5
AudioBubble On

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