GLOBAL

Row

Total Confirmed Cases

1,916,838

Total Death Cases

118,854

Total Recovery Cases

445,435

Row

Emotions on Twitter towards COVID-19

COVID-19 WordCloud

Row

Highest Confirmed

579486
UnitedStates

Highest Recovered

78756
China

Highest Death

23252
UnitedStates

TOP 10

Row

Confirmed Cases In the Most Affected Regions

Death Cases In the Most Affected Regions

Row

Serious Cases In the Most Affected Regions

Recovery Cases In the Most Affected Regions

AFRICA


Row

Total Confirmed Cases in Africa

14,884

Total Death Cases in Africa

808

Total Recovery Cases in Africa

2,168

Row

Confirmed Cases In Africa

Recovery Cases In Africa

AFRICA Cont


Row

Highest Confirmed Cases In Africa

2272
SouthAfrica

Highest Recovered Cases In Africa

488
Egypt

Highest Death Cases In Africa

313
Algeria

Row

Death Cases In Africa

Serious Cases In Africa

---
title: "COVID-19 Dashboard"
author: "dataSTAPLES"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidytext)
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

twitter_token <- create_token(
  app = "iSabiWey",
  consumer_key = "kwXvLHNXVFzM6qtHnPV2EZuan",
  consumer_secret = "FBODVaiqPjjVxQzGn33aWYCoKFdbP01oxUUQEhwGkqZHWDdZpm",
  access_token = "122035719-7yILa8vgOYssuFwvpII3jYvIxZ5Oqh80mXRiFkqI",
  access_secret = "l7RZGmToy6WcS9jSZ0OH2iTOqrMW0NazmEqKWcNNRjwxJ")
ww3 <- search_tweets(q = "Virus",
                               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://ncov2019.live/data"
globalcovid <- url %>%
xml2::read_html() %>%
html_nodes(xpath='//*[@id="sortable_table_global"]') %>%
html_table()
globalcovid <- globalcovid[1]

x <- (globalcovid[[1]][["Confirmed"]][2:11]) 
x <- as.numeric(gsub(",","",x,fixed=TRUE))
y <- (globalcovid[[1]][["Recovered"]][2:11])
y <- as.numeric(gsub(",","",y,fixed=TRUE))
d <- (globalcovid[[1]][["Deceased"]][2:11])
d <- as.numeric(gsub(",","",d,fixed=TRUE))
ac <- (globalcovid[[1]][["Serious"]][2:11])
ac <- as.numeric(gsub(",","",ac,fixed=TRUE))
r <- (globalcovid[[1]][["Name"]][2:11])
r <- gsub("[^a-zA-Z]", "", r)


maxa <- (globalcovid[[1]][["Confirmed"]][2:11])
maxa <- as.numeric(gsub(",","",maxa,fixed=TRUE))
maxal <- max(maxa)

maxalcountry <- r[maxa == maxal]
maxalcountry <- gsub("[^a-zA-Z]", "", maxalcountry)



maxr <- (globalcovid[[1]][["Recovered"]][2:11])
maxr <- as.numeric(gsub(",","",maxr,fixed=TRUE))
maxrl <- max(maxr)

maxrlcountry <- r[maxr == maxrl]
maxrlcountry <- gsub("[^a-zA-Z]", "", maxrlcountry)



maxd <- (globalcovid[[1]][["Deceased"]][2:11])
maxd <- as.numeric(gsub(",","",maxd,fixed=TRUE))
maxdl <- max(maxd)

maxdcountry <- r[maxd == maxdl]
maxdcountry <- gsub("[^a-zA-Z]", "", maxdcountry)



Confirmed <- globalcovid[[1]][["Confirmed"]][1]
Deceased <- globalcovid[[1]][["Deceased"]][1]
Recovered <- globalcovid[[1]][["Recovered"]][1]


url1 <- "https://ncov2019.live/data"
africacovid <- url1 %>%
xml2::read_html() %>%
html_nodes(xpath='//*[@id="sortable_table_africa"]') %>%
html_table()
africacovid <- africacovid[1]

afx <- (africacovid[[1]][["Confirmed"]][2:16]) 
afx <- as.numeric(gsub(",","",afx,fixed=TRUE))
afy <- (africacovid[[1]][["Recovered"]][2:16])
afy <- as.numeric(gsub(",","",afy,fixed=TRUE))
afd <- (africacovid[[1]][["Deceased"]][2:16])
afd <- as.numeric(gsub(",","",afd,fixed=TRUE))
afac <- (africacovid[[1]][["Serious"]][2:16])
afac <- as.numeric(gsub(",","",afac,fixed=TRUE))
afr <- (africacovid[[1]][["Name"]][2:16])
afr <- gsub("[^a-zA-Z]", "", afr)


afmaxa <- (africacovid[[1]][["Confirmed"]][2:16])
afmaxa <- as.numeric(gsub(",","",afmaxa,fixed=TRUE))
afmaxal <- max(afmaxa)

afmaxalcountry <- afr[afmaxa == afmaxal]
afmaxalcountry <- gsub("[^a-zA-Z]", "", afmaxalcountry)



afmaxr <- (africacovid[[1]][["Recovered"]][2:16])
afmaxr <- as.numeric(gsub(",","",afmaxr,fixed=TRUE))
afmaxrl <- max(afmaxr)

afmaxrlcountry <- afr[afmaxr == afmaxrl]
afmaxrlcountry <- gsub("[^a-zA-Z]", "", afmaxrlcountry)



afmaxd <- (africacovid[[1]][["Deceased"]][2:16])
afmaxd <- as.numeric(gsub(",","",afmaxd,fixed=TRUE))
afmaxdl <- max(afmaxd)

afmaxdcountry <- afr[afmaxd == afmaxdl]
afmaxdcountry <- gsub("[^a-zA-Z]", "", afmaxdcountry)



afConfirmed <- africacovid[[1]][["Confirmed"]][1]
afDeceased <- africacovid[[1]][["Deceased"]][1]
afRecovered <- africacovid[[1]][["Recovered"]][1]






```
# 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://ncov2019.live/

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")

```



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 Confirmed

```{r}

valueBox(maxal, icon = "fa-bed")

```
```{r}

valueBox(maxalcountry)

```



### Highest Recovered

```{r}

valueBox(maxrl, icon = "fa-users")

```

```{r}

valueBox(maxrlcountry)

```

### Highest Death

```{r}

valueBox(maxdl, icon = "fa-bed")

```

```{r}

valueBox(maxdcountry)

```


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=FALSE )

```

### Death Cases In the Most Affected Regions

```{r}
barplot(height=d,
        col="#69b3a9",
        names.arg=r,cex.names=0.7,
        las=2,  horiz=FALSE )

```


Row
-----------------------------------------------------------------------

### Serious Cases In the Most Affected Regions

```{r}
barplot(height=ac,
        col="#69b3a9",
        names.arg=r,cex.names=0.7,
        las=2, horiz=FALSE )

```

### Recovery Cases In the Most Affected Regions

```{r}
barplot(height=y,
        col="#69b3a9",
        names.arg=r,cex.names=0.7,
        las=2,  horiz=FALSE )

```



AFRICA
=======================================================================

-----------------------------------------------------------------------

Row
-----------------------------------------------------------------------

### Total Confirmed Cases in Africa

```{r}

valueBox(afConfirmed, icon = "fa-bed")

```

### Total Death Cases in Africa

```{r}

valueBox(afDeceased, icon = "fa-bed")

```


### Total Recovery Cases in Africa

```{r}

valueBox(afRecovered, icon = "fa-users")

```

Row
-----------------------------------------------------------------------

### Confirmed Cases In Africa

```{r}
barplot(height=afx,
        col="#69b3a9",
        names.arg=afr,cex.names=0.7,
        las=2, horiz=FALSE )

```

### Recovery Cases In Africa

```{r}
barplot(height=afy,
        col="#69b3a9",
        names.arg=afr,cex.names=0.7,
        las=2,  horiz=FALSE )

```




AFRICA Cont
=======================================================================

-----------------------------------------------------------------------

Row
-----------------------------------------------------------------------

### Highest Confirmed Cases In Africa

```{r}

valueBox(afmaxal, icon = "fa-bed")

```
```{r}

valueBox(afmaxalcountry)

```



### Highest Recovered Cases In Africa

```{r}

valueBox(afmaxrl, icon = "fa-users")

```

```{r}

valueBox(afmaxrlcountry)

```

### Highest Death Cases In Africa

```{r}

valueBox(afmaxdl, icon = "fa-bed")

```

```{r}

valueBox(afmaxdcountry)

```




Row
-----------------------------------------------------------------------

### Death Cases In Africa

```{r}
barplot(height=afd,
        col="#69b3a9",
        names.arg=afr,cex.names=0.7,
        las=2, horiz=FALSE )

```

### Serious Cases In Africa

```{r}
barplot(height=afac,
        col="#69b3a9",
        names.arg=afr,cex.names=0.7,
        las=2,  horiz=FALSE )

```