I want to use ChkClassWord(this works fine for single input but not when csv is chosen) function within analyze2. The csv file has below values.
Name
Good name
name bad
good price
I am getting output as below.(column wise)
Name | NameQuality | Explanation | Name | NameQuality | Explanation |
---|---|---|---|---|---|
Good name | Good | name bad | Bad | NoClassWord |
Could someone help me get the results rowwise like
Name NameQuality Explanation
Good name Good
name bad Bad NoClassWord
library(plyr)
library(shiny)
u <- fluidPage(
headerPanel('Business term name'),
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv', 'text/comma-separated- values,text/plain', '.csv'))
,
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
'Comma')
#actionButton("goButton","Upload Data")
)
,
mainPanel(
tableOutput(outputId = 'table')
))
server=function(input, output){
output$table <- renderTable({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
y <- read.table(inFile$datapath, header=input$header,sep=input$sep)
ChkClassWord <- function(x) {
a <- grepl("[!#$%*,:;<=>@^_`|~{}]", x)
n = c('name','flag','description','rate','average','type','duration','code','percent','percentage','title','name','number','average')
if ((!(word(tolower(x),-1) %in% n)) & (a == 'TRUE')) {
Name <- c(x)
NameQuality<-c("Bad")
Explanation<-c("NoClassWord and special characters")
df <- data.frame(Name,NameQuality,Explanation)}
else if (!(word(tolower(x),-1) %in% n)) {
Name <- c(x)
NameQuality<-c("Bad")
Explanation<-c("NoClassWord")
df <- data.frame(Name,NameQuality,Explanation)}
else if (a == 'TRUE'){
Name <- c(x)
NameQuality<-c("Bad")
Explanation <-c("Special characters used")
df <- data.frame(Name,NameQuality,Explanation)}
else {
Name <- c(x)
NameQuality<-c("Good")
Explanation <-c(" ")
df <- data.frame(Name,NameQuality,Explanation)
}
}
analyze2 <-function(y) {
for (f in seq_along(y)) {
fdata <- read.csv(inFile$datapath, header = TRUE)
res <- (apply(fdata, 1, ChkClassWord))
res <- cbind.data.frame(res)
}
return(res)
}
z<-analyze2(input$file1)
return(z)
})
}
shinyApp(ui=u, server=server)