Hi Adresrcs, here is my shiny app code. It's a little messy though:
if(interactive()){
library(shiny)
library(shinyalert)
library(shinycssloaders)
library(shinythemes)
library(shinyWidgets)
library(shinyjs)
library(SentimentAnalysis)
library(textclean)
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"))))))),
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"))
})
}
}
shinyApp(ui=ui,server=server)
Here is the log from the deployed app:
2020-05-14T15:52:54.056269+00:00 shinyapps[2244614]: Server version: 1.8.2-10
2020-05-14T15:52:54.056270+00:00 shinyapps[2244614]: LANG: en_GB.UTF-8
2020-05-14T15:52:54.056345+00:00 shinyapps[2244614]: R version: 3.6.0
2020-05-14T15:52:54.056346+00:00 shinyapps[2244614]: shiny version: 1.4.0.2
2020-05-14T15:52:54.056347+00:00 shinyapps[2244614]: httpuv version: 1.5.2
2020-05-14T15:52:54.056349+00:00 shinyapps[2244614]: RJSONIO version: (none)
2020-05-14T15:52:54.056348+00:00 shinyapps[2244614]: jsonlite version: 1.6.1
2020-05-14T15:52:54.056366+00:00 shinyapps[2244614]: htmltools version: 0.4.0
2020-05-14T15:52:54.056488+00:00 shinyapps[2244614]: Using pandoc: /opt/connect/ext/pandoc2
2020-05-14T15:52:54.056348+00:00 shinyapps[2244614]: rmarkdown version: (none)
2020-05-14T15:52:54.056348+00:00 shinyapps[2244614]: knitr version: (none)
2020-05-14T15:52:54.222678+00:00 shinyapps[2244614]: Using jsonlite for JSON processing
2020-05-14T15:52:54.233534+00:00 shinyapps[2244614]:
2020-05-14T15:52:54.233535+00:00 shinyapps[2244614]: Starting R with process ID: '82'
2020-05-14T15:52:54.265375+00:00 shinyapps[2244614]: Error in value[[3L]](cond) : object 'server' not found
2020-05-14T15:52:54.265377+00:00 shinyapps[2244614]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2020-05-14T15:52:54.265378+00:00 shinyapps[2244614]: Execution halted
2020-05-14T16:00:01.903062+00:00 shinyapps[2244614]: Server version: 1.8.2-10
2020-05-14T16:00:01.903119+00:00 shinyapps[2244614]: LANG: en_GB.UTF-8
2020-05-14T16:00:01.903122+00:00 shinyapps[2244614]: shiny version: 1.4.0.2
2020-05-14T16:00:01.903121+00:00 shinyapps[2244614]: R version: 3.6.0
2020-05-14T16:00:01.903122+00:00 shinyapps[2244614]: httpuv version: 1.5.2
2020-05-14T16:00:01.903123+00:00 shinyapps[2244614]: rmarkdown version: (none)
2020-05-14T16:00:01.903123+00:00 shinyapps[2244614]: knitr version: (none)
2020-05-14T16:00:01.903123+00:00 shinyapps[2244614]: jsonlite version: 1.6.1
2020-05-14T16:00:01.903124+00:00 shinyapps[2244614]: RJSONIO version: (none)
2020-05-14T16:00:01.903124+00:00 shinyapps[2244614]: htmltools version: 0.4.0
2020-05-14T16:00:01.903278+00:00 shinyapps[2244614]: Using pandoc: /opt/connect/ext/pandoc2
2020-05-14T16:00:02.069633+00:00 shinyapps[2244614]: Using jsonlite for JSON processing
2020-05-14T16:00:02.079726+00:00 shinyapps[2244614]:
2020-05-14T16:00:02.079727+00:00 shinyapps[2244614]: Starting R with process ID: '23'
2020-05-14T16:00:02.112496+00:00 shinyapps[2244614]: Error in value[[3L]](cond) : object 'server' not found
2020-05-14T16:00:02.112499+00:00 shinyapps[2244614]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2020-05-14T16:00:02.112500+00:00 shinyapps[2244614]: Execution halted
2020-05-14T16:00:22.583323+00:00 shinyapps[2244614]: Server version: 1.8.2-10
2020-05-14T16:00:22.583326+00:00 shinyapps[2244614]: LANG: en_GB.UTF-8
2020-05-14T16:00:22.583356+00:00 shinyapps[2244614]: R version: 3.6.0
2020-05-14T16:00:22.583357+00:00 shinyapps[2244614]: shiny version: 1.4.0.2
2020-05-14T16:00:22.583357+00:00 shinyapps[2244614]: httpuv version: 1.5.2
2020-05-14T16:00:22.583358+00:00 shinyapps[2244614]: rmarkdown version: (none)
2020-05-14T16:00:22.583358+00:00 shinyapps[2244614]: knitr version: (none)
2020-05-14T16:00:22.583358+00:00 shinyapps[2244614]: jsonlite version: 1.6.1
2020-05-14T16:00:22.583379+00:00 shinyapps[2244614]: htmltools version: 0.4.0
2020-05-14T16:00:22.583379+00:00 shinyapps[2244614]: RJSONIO version: (none)
2020-05-14T16:00:22.583566+00:00 shinyapps[2244614]: Using pandoc: /opt/connect/ext/pandoc2
2020-05-14T16:00:22.741154+00:00 shinyapps[2244614]: Using jsonlite for JSON processing
2020-05-14T16:00:22.750753+00:00 shinyapps[2244614]:
2020-05-14T16:00:22.750754+00:00 shinyapps[2244614]: Starting R with process ID: '39'
2020-05-14T16:00:22.779959+00:00 shinyapps[2244614]: Error in value[[3L]](cond) : object 'server' not found
2020-05-14T16:00:22.779960+00:00 shinyapps[2244614]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2020-05-14T16:00:22.779973+00:00 shinyapps[2244614]: Execution halted