Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 212032

R Shiny showing dataframe (Text Mining)

$
0
0

i try to make sentiment analysis using R Shiny, this is my code.

Server.r

library(shiny)
library(DT)
library(tm)

clean_data = function(mydata){

  ##CLEANING DATASET##
  #removeURL
  removeURL <- function(x) gsub("http[^[:space:]]*", "", x)
  noURL <- tm_map(corpus, removeURL)

  #removeMention
  remove.mention <- function(x) gsub("@\\S+", "", x)
  noMention <- tm_map(noURL, remove.mention)


  **AND ANOTHER PREPROCESSING STEP**
  return(mydata)

}

#UPLOAD DATA
function(input, output, session) {
  mydata <- reactive({
    inFile <- input$finput
    if(is.null(inFile)){return()}
    read.csv(inFile$datapath, header = TRUE, sep = ',', row.names = NULL)
  })

  #OUTPUT DATAFRAME
  output$fData <- DT::renderDataTable({
    DT::datatable(mydata(),
                  options = list(
                    initComplete = JS(
                      "function(settings, json) {",
                      "$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});",
                      "}"),
                    orderClasses = TRUE,searchHighlight = TRUE)) 
  })

    #PREPROCESSING DATA
  getText <- reactive({
    text <- mydata$text
    text
  })

  prep <- reactive({
    corpus <- Corpus(VectorSource(getText))
    clean_data()
  })

  output$preData <- renderTable({
    prep()
  })

}

UI.r


#
library(DT)
library(shiny)
library(shinythemes)


# -----------UI-----------
ui <- fluidPage(

titlePanel("Twitter Text Analysis"),

  sidebarLayout(
    sidebarPanel(
      fileInput("finput",label = h3("Upload File CSV"))),
    mainPanel(
      tabsetPanel(type = "tab",
                  tabPanel("Dataset",
                           DT::dataTableOutput("fData")),
                  tabPanel("Preprocessing",
                           DT::dataTableOutput("preData"))
      )
    )
  )
)

there is no problem displaying the dataset in the dataset tabpanel, I try to show dataframe after preprocessing step, But, it's show Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character' in tabpanel Preprocessing.

I try to make dataframe from prep with this code

df <- reactive({
    dataframe <-data.frame(text=unlist(sapply(prep, `[`)), stringsAsFactors=F)
  })

But always show Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character' What should i do? Thank you


Viewing all articles
Browse latest Browse all 212032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>