---
title: "COVID-19 Dashboard"
author: "dataSTAPLES"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(xml2)
library(tm)
library(rtweet)
# plotting and pipes - tidyverse!
library(ggplot2)
library(plotly)
library(plyr)
library(wordcloud2)
library(syuzhet)
library(lubridate)
library(scales)
library(reshape2)
library(dplyr)
library(rvest)
library(shiny)
library(NLP)
# text mining library
library(tidytext)
twitter_token <- create_token(
app = "iSabiWey",
consumer_key = "kwXvLHNXVFzM6qtHnPV2EZuan",
consumer_secret = "FBODVaiqPjjVxQzGn33aWYCoKFdbP01oxUUQEhwGkqZHWDdZpm",
access_token = "122035719-7yILa8vgOYssuFwvpII3jYvIxZ5Oqh80mXRiFkqI",
access_secret = "l7RZGmToy6WcS9jSZ0OH2iTOqrMW0NazmEqKWcNNRjwxJ")
ww3 <- search_tweets(q = "COVID-19",
n = 1000)
# Make some noisily increasing data
world_war_3 <- ww3$text
class(world_war_3)
corpus <- Corpus(VectorSource(world_war_3))
corpus <- tm_map(corpus, tolower)
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
cleanset <- tm_map(corpus, removeWords,stopwords('english'))
removeURL <- function(x) gsub('http[[:alnum:]]*', '', x)
cleanset <- tm_map(cleanset, content_transformer(removeURL))
inspect(cleanset[1:5])
cleanset <- tm_map(cleanset, stripWhitespace)
tdm <- TermDocumentMatrix(cleanset)
tdm
tdm <- as.matrix(tdm)
w <- rowSums(tdm)
w <- subset(w, w>=10)
w <- data.frame(names(w), w)
colnames(w) <- c('word', 'freq')
s <- get_nrc_sentiment(world_war_3)
url <- "https://www.worldometers.info/coronavirus/"
globalcovid <- url %>%
xml2::read_html() %>%
html_nodes(xpath='//*[@id="main_table_countries_today"]') %>%
html_table()
globalcovid <- globalcovid[1]
x <- (globalcovid[[1]][["TotalCases"]][1:10])
x <- as.numeric(gsub(",","",x,fixed=TRUE))
ac <- (globalcovid[[1]][["ActiveCases"]][1:10])
ac <- as.numeric(gsub(",","",ac,fixed=TRUE))
y <- (globalcovid[[1]][["TotalRecovered"]][1:10])
y <- as.numeric(gsub(",","",y,fixed=TRUE))
d <- (globalcovid[[1]][["TotalDeaths"]][1:10])
d <- as.numeric(gsub(",","",d,fixed=TRUE))
a <- (globalcovid[[1]][["ActiveCases"]][1:10])
a <- as.numeric(gsub(",","",a,fixed=TRUE))
r <- (globalcovid[[1]][["Country,Other"]][1:10])
maxa <- (globalcovid[[1]][["ActiveCases"]][1:10])
maxa <- as.numeric(gsub(",","",maxa,fixed=TRUE))
maxal <- max(maxa)
maxalcountry <- r[maxa == maxal]
maxalcountry
maxn <- (globalcovid[[1]][["NewCases"]][1:10])
maxn <- as.numeric(gsub(",","",maxn,fixed=TRUE))
maxn[is.na(maxn[1:10])] = 0
maxnl <- max(maxn)
maxncountry <- r[maxn == maxnl]
maxncountry
maxd <- (globalcovid[[1]][["NewDeaths"]][1:10])
maxd <- as.numeric(gsub(",","",maxd,fixed=TRUE))
maxd[is.na(maxd[1:10])] = 0
maxdl <- max(maxd)
maxdcountry <- r[maxd == maxdl]
maxdcountry
Confirmed <- globalcovid[[1]][["TotalCases"]][207]
Deceased <- globalcovid[[1]][["TotalDeaths"]][207]
Recovered <- globalcovid[[1]][["TotalRecovered"]][207]
Active <- globalcovid[[1]][["ActiveCases"]][207]
```
# Introduction {.sidebar}
This dashboard shows the latest updates on the COVID-19 outbreak. Data was scrapped from two sources using R.
The data collected was analyzed using NLP, sentiment analysis and data visualization with R.
Data Sources:
* https://twitter.com/
* https://www.worldometers.info/coronavirus/
P.S. You can scroll across the multiple VIZ (GLOBAL,TOP 10,AFRICA...)
This dashboard was last updated at
```{r}
Sys.time()
```
GLOBAL
=======================================================================
Row
-----------------------------------------------------------------------
### Total Confirmed Cases
```{r}
valueBox(Confirmed, icon = "fa-bed")
```
### Total Death Cases
```{r}
valueBox(Deceased, icon = "fa-bed")
```
### Total Recovery Cases
```{r}
valueBox(Recovered, icon = "fa-users")
```
### Total Active Cases
```{r}
valueBox(Active, icon = "fa-bed")
```
Row
-----------------------------------------------------------------------
### Emotions on Twitter towards COVID-19
```{r}
barplot(colSums(s),
las = 2,
col = rainbow(10),cex.names=0.7,
ylab = 'Count',
)
```
### COVID-19 WordCloud
```{r}
wordcloud2(w,
size = 0.7,
shape = 'square',
minSize = 1)
```
Row
-----------------------------------------------------------------------
### Highest New Death Cases Today
```{r}
valueBox(maxdl, icon = "fa-bed")
```
```{r}
valueBox(maxdcountry)
```
### Highest New Confirmed Cases Today
```{r}
valueBox(maxnl, icon = "fa-bed")
```
```{r}
valueBox(maxncountry)
```
### Highest Active Cases Today
```{r}
valueBox(maxal, icon = "fa-bed")
```
```{r}
valueBox(maxalcountry)
```
TOP 10
=======================================================================
Row
-----------------------------------------------------------------------
### Confirmed Cases In the Most Affected Regions
```{r}
barplot(height=x,
col="#69b3a9",
names.arg=r,cex.names=0.7,
las=2, horiz=TRUE )
```
### Death Cases In the Most Affected Regions
```{r}
barplot(height=d,
col="#69b3a9",
names.arg=r,cex.names=0.7,
las=2, horiz=TRUE )
```
Row
-----------------------------------------------------------------------
### Active Cases In the Most Affected Regions
```{r}
barplot(height=ac,
col="#69b3a9",
names.arg=r,cex.names=0.7,
las=2, horiz=TRUE )
```
### Recovery Cases In the Most Affected Regions
```{r}
barplot(height=y,
col="#69b3a9",
names.arg=r,cex.names=0.7,
las=2, horiz=TRUE )
```
AFRICA
=======================================================================
Coming Soon
-----------------------------------------------------------------------
### VIZ is Coming Soon
```{r}
```