Please, I am trying to upgrade my published shiny app, with a word cloud and term frequency table. Here is the link to my published app, which I want to upgrade with word cloud features mavisanalytic.shinyapps.io/mavisanalytic. However, I am unable to create and display a term frequency table beside the wordcloud plot, as I get the following error message in my console:
Warning in tm_map.SimpleCorpus(corp, removeNumbers) :
transformation drops documents
Warning in tm_map.SimpleCorpus(corp, removePunctuation) :
transformation drops documents
Warning in tm_map.SimpleCorpus(corp, stripWhitespace) :
transformation drops documents
Warning in tm_map.SimpleCorpus(corp, tolower) :
transformation drops documents
Warning in tm_map.SimpleCorpus(corp, removeWords, stopwords("english")) :
transformation drops documents
Warning: Error in FUN: could not find function "FUN"
135: tm_map.SimpleCorpus
133: <reactive:tcl> [C:\Users\Idiaye\Documents\R data\mavisanalytic/app.R#510]
117: tcl
114: <reactive:termCount.df> [C:\Users\Idiaye\Documents\R data\mavisanalytic/app.R#514]
98: termCount.df
95: func [C:\Users\Idiaye\Documents\R data\mavisanalytic/app.R#545]
82: origRenderFunc
81: output$cloudable
1: runApp
Furthermore, ever since I created a word cloud in my shiny app, the other plots have stopped displaying. Here is my code. It is a little messy:
library(shiny)
library(shinyalert)
library(shinycssloaders)
library(shinythemes)
library(shinyWidgets)
library(shinyjs)
library(SentimentAnalysis)
library(SnowballC)
library(textclean)
library(wordcloud)
library(wordcloud2)
library(reactable)
library(rsconnect)
library(curl)
library(tm)
options(spinner.color="#3498db",
spinner.color.background="#ffffff",
spinner.size=1)
ui<-list(useShinyjs(),navbarPage(strong("Mavis Analytic"),theme=shinytheme("cerulean"),
windowTitle="Mavis Analytic",fluid=TRUE,inverse=FALSE,
tabPanel(strong("Opinion Miner"),icon=icon("table"),useShinyalert(),
setBackgroundColor("white"),setBackgroundImage(src="white.jpg"),
sidebarLayout(
sidebarPanel(width=3,
img(src="logo.jpg",height=130,width=150),
h4(strong("Enter your texts in these fields")),
actionButton("clear",strong("Clear Fields"),icon=icon("broom")),br(),br(),
textAreaInput("text","Text Field 1",value="It is a beautiful day"),
textAreaInput("texts","Text Field 2",value="I am happy to be here"),
textAreaInput("word","Text Field 3",value="Let's have some fun"),
textAreaInput("words","Text Field 4",value="It has been a bad outing"),
textAreaInput("wordy","Text Field 5",value="I dislike clowns"),
actionButton("run",strong("Run Analysis"),icon=icon("caret-right")),br(),hr(),h5(strong("The number of words entered into each text field:")),reactableOutput("count",width="40%")),
mainPanel(h4("The Opinion Miner is a tool for conducting sentiment analysis. It is useful for analyzing and scoring the kinds of sentiments expressed in texts, such as in literature, social media posts, or product reviews."),hr(),h3(strong("Table of Sentiment Scores")),withSpinner(reactableOutput("table"),type=1),downloadButton("download",strong("Download Table")),br(),br(),
column(4,selectInput("choice","Select Sentiment Score to Plot",choices=c("QDAP","LoughranM","HarvardIV"))),column(4,selectInput("color","Select Color",choices=c("Blue","Red","Green","Yellow","Purple"))),
fluidRow(column(6,withSpinner(plotOutput("plot",height=350,width=400),type=1)),column(6,withSpinner(plotOutput("graph",height=350,width=400),type=1))),
fluidRow(column(6,downloadButton("plot.down",strong("Download Graph")))),
fluidRow(column(6,withSpinner(wordcloud2Output("cloud"),type=1)),column(6,withSpinner(reactableOutput("cloudable"),type=1)))))),
tabPanel(strong("Financial Ratios Calculator"),icon=icon("chart-bar"),
sidebarLayout(
sidebarPanel(width=2,h4(strong("Profit figures:")),
actionButton("delete",strong("Clear Fields"),icon=icon("broom")),br(),br(),
textInput("num","Profit 1",value="100000",width=150),
textInput("numb","Profit 2",value="150000",width=150),
textInput("number","Profit 3",value="200000",width=150),
textInput("numbers","Profit 4",value="250000",width=150),
textInput("numbered","Profit 5",value="300000",width=150),
hr(),
h4(strong("Turnover figures:")),
actionButton("remove",strong("Clear Fields"),icon=icon("broom")),br(),br(),
textInput("fig","Turnover 1",value="350000",width=150),
textInput("figs","Turnover 2",value="300000",width=150),
textInput("figu","Turnover 3",value="420000",width=150),
textInput("figur","Turnover 4",value="600000",width=150),
textInput("figure","Turnover 5",value="550000",width=150),
actionButton("go",strong("Calculate Ratio"),icon=icon("caret-right")),
hr(),
h4(strong("Receivables figures:")),
actionButton("vanish",strong("Clear Fields"),icon=icon("broom")),br(),br(),
textInput("deb","Receivables 1",value="150000",width=150),
textInput("debt","Receivables 2",value="100000",width=150),
textInput("debts","Receivables 3",value="50000",width=150),
textInput("debtor","Receivables 4",value="80000",width=150),
textInput("debtors","Receivables 5",value="170000",width=150),
actionButton("away",strong("Calculate Ratio"),icon=icon("caret-right"))),
mainPanel(h4("The Financial Ratios Calculator makes possible a comparative analysis of a company's profitability and efficiency ratios over time."),hr(),
h3(strong("Profitability Ratios")),h4("(Profit/Turnover): Calculates how much profit margin (%) a company makes on its sales"),fluidRow(column(6,withSpinner(plotOutput("bar",),type=1)),column(6,withSpinner(plotOutput("pie"),type=1))),
fluidRow(column(6,downloadButton("drop",strong("Download Bar Plot"))),column(6,downloadButton("fall",strong("Download Pie Chart")))),hr(),
h3(strong("Efficiency Ratios")),h4("(Receivables/Turnover): Calculates the average length of time (in days) it takes for a company to recover its debts"),
fluidRow(column(6,withSpinner(plotOutput("sphere"),type=1)),column(6,withSpinner(plotOutput("bin"),type=1))),
fluidRow(column(6,downloadButton("down",strong("Download Pie Chart"))),column(6,downloadButton("plummet",strong("Download Bar Plot")))))
)),
tabPanel(strong("About Mavis Analytic"),icon=icon("info"),mainPanel(h4(div(style="color:#5499c7","Mavis Analytic is designed as a multi-functional web application, with a variety of features that make it a modern business tool.
It currently incorporates tools for conducting sentiment analysis and financial performance evaluation. The goal of the designers of Mavis Analytic, Mavis Naissance Consulting,
is to keep expanding the scope of the application, by creating more functions that will make it a very versatile software for a wide range of business uses. ")),img(src="New.jpg",height=150,width=150))),
tabPanel(strong("Send Us Your Feedback"),icon=icon("envelope"),
HTML("<iframe src=https://docs.google.com/forms/d/e/1FAIpQLSex-eKi33LdmZE7L3PwjWm4tFbFoEIw_L_KUvsSi6kgdXgJPA/viewform?embedded=true width=1400 height=1000 frameborder=0 marginheight=0 marginwidth=0>Loading.</iframe>")),
navbarMenu(strong("More"),
tabPanel(strong("Graphs and Charts"),icon=icon("chart-bar"),sidebarLayout(sidebarPanel(width=3, selectInput("select","Select Variable to Plot",choice=c(
"Indegree","Outdegree","Degree","Normalized",
"Domain","Proximity","Modularity","Clusters"
),selected="Modularity"),sliderInput("slide","Change Pie Chart Angle",min=45,max=180,animate=TRUE,value=45,step=1)),
mainPanel(fluidRow(column(6,plotOutput("draw")),column(6,plotOutput("art"))),br(),
fluidRow(column(6,plotOutput("paint")),column(6,plotOutput("part")))))),
tabPanel(strong("Tables"),icon=icon("table"),
mainPanel(h3("Network data pulled from Twitter interactions on different subjects "),actionButton("detail",strong("Table Info")),downloadButton("table.down",strong("Download Table")),reactableOutput("metrics.table"),hr(),
actionButton("more",strong("Table Info")),downloadButton("flat",strong("Download Table")), reactableOutput("freedom.table"))),
tabPanel(strong("Library"),icon=icon("file-pdf"),
fluidRow(column(6,tags$iframe(style="height:400px;width:100%;scrolling=yes",src="analysis.pdf")),column(6,tags$iframe(style="height:400px;width:100%;scrolling=yes",src="Audits.pdf"))),br(),
fluidRow(column(6,tags$iframe(style="height:400px;width:100%;scrolling=yes",src="pricing.pdf")),column(6,tags$iframe(style="height:400px;width:100%;scrolling=yes",src="tech.pdf")))))
))
server<-function(input,output,session){
observeEvent(input$clear,{
updateTextAreaInput(session,"text",value="",placeholder="Enter new text")
updateTextAreaInput(session,"texts",value="",placeholder="Enter new text")
updateTextAreaInput(session,"word",value="",placeholder="Enter new text")
updateTextAreaInput(session,"words",value="",placeholder="Enter new text")
updateTextAreaInput(session,"wordy",value="",placeholder="Enter new text")
})
observeEvent(input$run,{
shinyalert(title="Running Analysis",text="Please be patient while the app cleans the texts and runs the analysis",
closeOnEsc=TRUE,confirmButtonText="OK",timer=10000,animation=TRUE,closeOnClickOutside=TRUE)
})
observeEvent(input$detail,{
shinyalert(title="Disease on Twitter",text="This table contains the metrics underlying the network of Twitter interactions about disease, using the #disease hashtag",
closeOnEsc=TRUE,closeOnClickOutside=TRUE,animation=TRUE,confirmButtonText="OK",timer=10000)
})
observeEvent(input$more,{
shinyalert(title="Freedom on Twitter",text="This table contains the statistical data of the Twitter conversation about freedom, using the #freedom hashtag",
closeOnEsc=TRUE,closeOnClickOutside=TRUE,animation=TRUE,confirmButtonText="OK",timer=10000)
})
observeEvent(input$delete,{
updateTextInput(session,"num",value="",placeholder="0")
updateTextInput(session,"numb",value="",placeholder="0")
updateTextInput(session,"number",value="",placeholder="0")
updateTextInput(session,"numbers",value="",placeholder="0")
updateTextInput(session,"numbered",value="",placeholder="0")
})
observeEvent(input$remove,{
updateTextInput(session,"fig",value="",placeholder="0")
updateTextInput(session,"figs",value="",placeholder="0")
updateTextInput(session,"figu",value="",placeholder="0")
updateTextInput(session,"figur",value="",placeholder="0")
updateTextInput(session,"figure",value="",placeholder="0")
})
observeEvent(input$vanish,{
updateTextInput(session,"deb",value="",placeholder="0")
updateTextInput(session,"debt",value="",placeholder="0")
updateTextInput(session,"debts",value="",placeholder="0")
updateTextInput(session,"debtor",value="",placeholder="0")
updateTextInput(session,"debtors",value="",placeholder="0")
})
doc<-reactive({c(if(nchar(input$text)>0){input$text},
if(nchar(input$texts)>0){input$texts},
if(nchar(input$word)>0){input$word},
if(nchar(input$words)>0){input$words},
if(nchar(input$wordy)>0){input$wordy}
)
})
profit<-reactive({
as.numeric(c(if(input$num>0){input$num},
if(input$numb>0){input$numb},
if(input$number>0){input$number},
if(input$numbers>0){input$numbers},
if(input$numbered>0){input$numbered}))
})
turnover<-reactive({
as.numeric(c(if(input$fig>0){input$fig},
if(input$figs>0){input$figs},
if(input$figu>0){input$figu},
if(input$figur>0){input$figur},
if(input$figure>0){input$figure}))})
receivables<-reactive({
as.numeric(c(if(input$deb>0){input$deb},
if(input$debt>0){input$debt},
if(input$debts>0){input$debts},
if(input$debtor>0){input$debtor},
if(input$debtors>0){input$debtors}))})
output$table.down<-downloadHandler(
filename=function(){
paste("Metrics",".csv",sep="")
},
content=function(file){
write.csv(disease,file)
}
)
output$flat<-downloadHandler(
filename=function(){
paste("Freedom",".csv",sep="")
},
content=function(file){
write.csv(freedom,file)
}
)
disease<-read.csv("metrics.csv",header=TRUE,sep=",")
disease.df<-data.frame(disease)
pie.data<-reactive({head(disease$Degree,n=8)})
bar.data<-reactive({head(freedom$Outdegree,n=6)})
freedom<-read.csv("Freedom.csv",header=TRUE,sep=",")
freedom.df<-data.frame(freedom)
data.X<-reactive({switch(input$select,
"Indegree"=disease$Indegree,
"Outdegree"=disease$Outdegree,
"Degree"=disease$Degree,
"Normalized"=disease$Normalized,
"Domain"=disease$Domain,
"Proximity"=disease$Proximity,
"Modularity"=disease$Modularity,
"Clusters"=disease$Clusters
)})
data.Y<-reactive({switch(input$choice,
"Indegree"=disease$Indegree,
"Outdegree"=disease$Outdegree,
"Degree"=disease$Degree,
"Normalized"=disease$Normalized,
"Domain"=disease$Domain,
"Proximity"=disease$Proximity,
"Modularity"=disease$Modularity,
"Clusters"=disease$Clusters
)})
output$metrics.table<-renderReactable({
reactable(disease.df,
searchable=TRUE,
outlined=TRUE,
highlight=TRUE,
bordered=TRUE,
striped=TRUE,
compact=TRUE,
defaultColDef=colDef(
align="center",
headerStyle=list(background="#5dade2")
))
})
output$freedom.table<-renderReactable({
reactable(freedom.df,
compact=TRUE,
striped=TRUE,
searchable=TRUE,
bordered=TRUE,
highlight=TRUE,
defaultColDef=colDef(
align="center",
headerStyle=list(background="#5dade2")
))
})
#This is the function for calculating profitability ratio
profitability<-function(profit,turnover){
profitability=round((profit/turnover)*100,1)
return(profitability)
}
profitability.ratio<-reactive({profitability(profit(),turnover())})
#This is the function for calculating efficiency ratio
efficiency<-function(receivables,turnover){
efficiency<-round((receivables/turnover)*365,1)
return(efficiency)
}
efficiency.reactive<-reactive({
efficiency(receivables(),turnover())
})
Analyze<-reactive({
round(analyzeSentiment(
replace_symbol(
replace_number(
replace_ordinal(
doc())))),1)})
QDAP<-reactive({Analyze()$SentimentQDAP})
LoughranM<-reactive({Analyze()$SentimentLM})
HarvardIV<-reactive({Analyze()$SentimentGI})
word.count<-reactive({countWords(doc(),removeStopwords=FALSE)})
tables<-reactive({
data.frame(QDAP(),LoughranM(),HarvardIV())
})
data<-reactive({switch(input$choice,
"QDAP"=tables()$QDAP,
"LoughranM"=tables()$LoughranM,
"HarvardIV"=tables()$HarvardIV)})
output$download<-downloadHandler(
filename=function(){
paste("table",".csv",sep="")
},
content=function(file){
write.csv(tables(),file)
}
)
output$drop<-downloadHandler(
filename=function(){
paste("Barplot",".jpg",sep="")
},
content=function(file){
jpeg(file)
barplot(profitability.ratio(),
col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"),
beside=TRUE,
border="white",
xlab="Years",
ylab="Margins in (%)")
dev.off()
}
)
output$fall<-downloadHandler(
filename=function(){
paste("Piechart",".jpg",sep="")
},
content=function(file){
jpeg(file)
pie(profitability.ratio(),radius=1.1,col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"),
border="white",
clockwise=TRUE,
init.angle=90,
labels=profitability.ratio())
dev.off()
}
)
output$down<-downloadHandler(
filename=function(){
paste("Piechart",".jpg",sep="")
},
content=function(file){
jpeg(file)
pie(efficiency.reactive(),radius=1.1,border="white",clockwise=TRUE,
init.angle=90,
labels=efficiency.reactive(),
col=c("#5dade2","#85c1e9","#3498db","#2e86c1","#2874a6"))
dev.off()
}
)
output$plummet<-downloadHandler(
filename=function(){
paste("Barplot",".jpg",sep="")
},
content=function(file){
jpeg(file)
barplot(efficiency.reactive(),
col=c("#5dade2","#85c1e9","#3498db","#2e86c1","#2874a6"),
border="white",
beside=TRUE,
xlab="Years",
ylab="Days")
dev.off()
}
)
output$plot.down<-downloadHandler(
filename=function(){
paste("Graph",".jpg",sep="")
},
content=function(file){
jpeg(file)
color<-switch(input$color,
"Blue"="#5dade2",
"Red"="#e74c3c",
"Green"="#1abc9c",
"Yellow"="#f7dc6f",
"Purple"="#a569bd")
barplot(data(),col=color,border="white",xlab="Texts",ylab="Sentiment Scores",main="Bar Plot of Sentiment Scores")
dev.off()
}
)
output$table<-renderReactable({
input$run
isolate(reactable(tables(),searchable=TRUE,bordered=TRUE,defaultColDef=colDef(
align="center",
headerStyle=list(background="#5dade2"),
style=function(value){
if(value>0){color<-"#27ae60"}
else if(value<0){color<-"#e74c3c"}
else{color<-"#5dade2"}
list(color=color,fontWeight="bold")
}),
highlight=TRUE,outlined=TRUE,striped=TRUE,filterable=FALSE,compact=TRUE,onClick="expand")
)
})
output$count<-renderReactable({
input$run
isolate(reactable(data.frame(word.count()),bordered=TRUE,striped=TRUE,compact=TRUE,
defaultColDef=colDef(
align="center",
headerStyle=list(background="#85c1e9"))
))
})
output$plot<-renderPlot({
color<-switch(input$color,
"Blue"="#5dade2",
"Red"="#e74c3c",
"Green"="#1abc9c",
"Yellow"="#f7dc6f",
"Purple"="#a569bd")
input$run
isolate(barplot(data(),col=color,border="white",xlab="Texts",ylab="Sentiment Scores",main="Bar Plot of Sentiment Scores"))
})
output$graph<-renderPlot({
input$run
isolate(plotSentiment(data(),xlab="Texts",ylab="Sentiment Scores"))
})
output$bar<-renderPlot({
input$go
isolate(barplot(profitability.ratio(),
col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"),
beside=TRUE,
border="white",
xlab="Years",
ylab="Margins in (%)"))})
output$pie<-renderPlot({
input$go
isolate(pie(profitability.ratio(),radius=1.1,col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"),
border="white",
clockwise=TRUE,
init.angle=90,
labels=profitability.ratio()))
})
output$sphere<-renderPlot({
input$away
isolate(
pie(efficiency.reactive(),radius=1.1,border="white",clockwise=TRUE,
init.angle=90,
labels=efficiency.reactive(),
col=c("#5dade2","#85c1e9","#3498db","#2e86c1","#2874a6"))
)
})
output$bin<-renderPlot({
input$away
isolate(
barplot(efficiency.reactive(),
col=c("#5dade2","#85c1e9","#3498db","#2e86c1","#2874a6"),
border="white",
beside=TRUE,
xlab="Years",
ylab="Days")
)
})
output$draw<-renderPlot({
hist(data.X(),border="white",col="#3498db",main="Variable Plots",xlab="Metrics")
})
output$art<-renderPlot({
plot(data.X(),disease$Modularity,col="#e74c3c",xlab="Metrics",ylab="Value",pch=20,
cex=2,type="h",main="Variable Plots")
})
output$paint<-renderPlot({
pie(pie.data(),radius=1.1,clockwise=TRUE,init.angle=input$slide,
border="white",col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"),main="Pie Chart of Degrees")
})
output$part<-renderPlot({
barplot(bar.data(),border="white",main="Bar Plot of Outdegrees",
xlab="Outdegrees",ylab="Values",col=c("#5dade2","#ec7063","#48c9b0","#a569bd","#f4d03f"))
})
tc<-reactive({Corpus(VectorSource(doc()))})
tcl<-reactive({tm_map(tc(),list(removeNumbers,removePunctuation,
stripWhitespace,removeWords,stopwords("english")))})
termCount.df<-reactive({data.frame(head(tcl(),10))})
word.cloud<-function(x){
if(is.character(x)){
corp<-Corpus(VectorSource(x))
corp<-tm_map(corp,removeNumbers)
corp<-tm_map(corp,removePunctuation)
corp<-tm_map(corp,stripWhitespace)
corp<-tm_map(corp,tolower)
corp<-tm_map(corp,removeWords,stopwords("english"))
tms<-TermDocumentMatrix(corp)
a<-as.matrix(tms)
v<-sort(rowSums(a),decreasing=TRUE)
d<-data.frame(Words=names(v),Frequency=as.numeric(v))
wordcloud2(d,size=0.2)}
}
text.cloud<-reactive({word.cloud(doc())})
output$cloud<-renderWordcloud2({
text.cloud()
})
output$cloudable<-renderReactable({
reactable(termCount.df())
})
}
shinyApp(ui=ui,server=server)
Thanks in anticipation of your advice.