首页 > 解决方案 > 使用 Shiny 和 FlexDashboard 运行饼图时出现问题

问题描述

我是 Stack Overflow 的新手,我也是 R 的初学者,但我正在努力改进。我想知道是否有人可以解决我创建带有区域选项的仪表板的问题。我从https://beta.rstudioconnect.com/jjallaire/shiny-eruptions/举了一个例子,你可以看到一些参考资料。在这次 Covid-19 危机期间,我正在尝试为我的国家意大利创建一个仪表板。提前谢谢

---
title: "Old Faithful Eruptions"
output: flexdashboard::flex_dashboard
runtime: shiny
---

```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(flexdashboard)
library(plotly)
library(covid19italy)
library(ggplot2)
library(dplyr)
 library(tidyr)
italy_province2 <- italy_province %>% 
    mutate(date=as.Date(date, format= "%y/%m/%d"))%>% 
     group_by(province_code) %>%  
     arrange(desc(date)) %>%
     slice(1)

```

Column {.sidebar}
-----------------------------------------------------------------------

Waiting time between eruptions and the duration of the eruption for the
Old Faithful geyser in Yellowstone National Park, Wyoming, USA.

```{r}
selectInput("region", label = "Region:",
            choices = c("Piemonte","Valle d'Aosta","Liguria","Lombardia","P.A. Bolzano",
                        "P.A. Trento","Veneto","Friuli Venezia 
                        Giulia","Emilia-Romagna","Marche","Toscana","Umbria","Lazio","Campania","Abruzzo","Molise",                          "Puglia","Basilicata","Calabria","Sicilia","Sardegna"  ), selected = "Piemonte")

```

Column
-----------------------------------------------------------------------

### Geyser Eruption Duration

```{r}
renderPlot({
  italy_province2 %>%
  filter(date == max(date), region_name == toString(input$region) %>%
  ggplot(labels = ~province_name, values = ~total_cases,
          textinfo="label+percent",
          type = 'pie') 
})

标签: rggplot2shinyplotlyflexdashboard

解决方案


推荐阅读