Flex Dashboard not working when I add the world map code in it

戏子无情 提交于 2020-05-31 04:57:45

问题


I have created a flex dashboard using R Markdown in RStudio for 'COVID-19 WORLDWIDE TRACKER'. I have created one line plot, one area plot and 2 column graphs. I want to add a world heat map in it. The data is here: mydata and x. Code is as follows:

---
title: "COVID-19 WORLDWIDE TRACKER"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
library(readxl)
library(rworldmap)
library(dplyr)
library(maps)
library(plyr)
library(gridExtra)

x <- read_excel("owid-covid-data.xlsx")
```

Page 1
===
row {data-height = 350}
---

### World Hotspots
```{r}
library(maps)
library(ggplot2)

mydata <- readxl::read_excel("mapdata1.xlsx")

mydata$Country[mydata$Country == "United States"] <- "USA"
mydata$Country[mydata$Country == "United Kingdom"] <- "UK"

world_map <- map_data("world")
world_map <- subset(world_map, region != "Antarctica")

ggplot(mydata) +
  geom_map(
    dat = world_map, map = world_map, aes(map_id = region),
    fill = "white", color = "#7f7f7f", size = 0.25
  ) +
  geom_map(map = world_map, aes(map_id = Country, fill = Cases), size = 0.25) +
  scale_fill_gradient(low = "#fff7bc", high = "#cc4c02", name = "Total Cases") +
  expand_limits(x = world_map$long, y = world_map$lat)
```


row {data-height=300} 
-----------------------------------------------------------------------
### Top 10 Countries
```{r}
p <- ggplot(x, aes(date, total_cases, color = location)) + geom_line()
ggplotly(p)
```


row {data-height=300} 
-----------------------------------------------------------------------
### Daily Comparison of New Cases and Deaths

```{r}
a <- ggplot(x, aes(date, new_cases, fill = location)) + geom_area()
ggplotly(a)
```


row {data-height=400} 
-----------------------------------------------------------------------

### Daily Comparison of Total Cases and Deaths

```{r}
b <- ggplot(x, aes(date, total_cases, fill = total_deaths)) + geom_col(position = "dodge")
ggplotly(b)
```

### Top Countries

```{r}
c <- ggplot(x, aes(total_cases_per_million, location)) + geom_col(position = "dodge")
ggplotly(c)
```

Without the world map code, the dashboard works perfectly fine. But when I add the world map code to it, the dashboard shows a white screen and no graphs at all. I am not able to understand why this is happening. Please help!

来源:https://stackoverflow.com/questions/61840195/flex-dashboard-not-working-when-i-add-the-world-map-code-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!