【发布时间】:2020-08-28 08:08:17
【问题描述】:
我是闪亮的新手,将ggplot 放入renderPlot 时遇到问题。如果 ggplot 单独运行,它运行良好,但是当我开始将它放入 renderPlot 时,它什么也没有。
代码如下:
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(shinythemes)
library(leaflet)
library(magrittr)
library(rvest)
library(readxl)
library(dplyr)
library(maps)
library(ggplot2)
library(reshape2)
library(plotly)
cv_continent <- read.csv("coronavirus_continent.csv")
ui <- bootstrapPage(
tags$head(includeHTML("gtag.html")),
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
"VISUALISATION LE COVID-19", id="nav",
tabPanel("GLOBAL",
sidebarPanel(
width= 20,
span(tags$i(h1("Visualiser la revolution globale du Covid-19 pendant 4 mois\n")), style="color:#045a8d"),
span(tags$i(h2("Diagramme en barre")), style="color:#045a8d"),
selectInput("condition","Choisir observation:",
choices = c("Cas","NouveauxCas","Décès","NouveauxDécès"))
),
plotOutput("image")
),
tabPanel("Continent",
sidebarLayout(
sidebarPanel(
span(tags$i(h4("Visualiser la revolution du Covid-19 par continent\n")), style="color:#045a8d"),
selectInput("continent","Choisir un continent:",
choices = c("Asie","Europe","Amérique_du_Nord","Amérique_du_Sud","Océanie"))
),
#mainPanel(
tabsetPanel(
tabPanel("Diagramme en barre pour chaque continent", plotlyOutput("barre")),
tabPanel("Diagramme sectoriel", plotlyOutput("sectoriel")),
tabPanel("Dendrogramme", plotlyOutput("dendrogramme"))
)
# )
)
)
)
)
server <- function(input, output){
ContinentInput <- reactive({
switch(input$continent,
"Asie" = Asia,
"Europe" = Europe,
"Amérique_du_Nord" = North_America,
"Amérique_du_Sud" = South_America,
"Océanie" = Oceania)
})
output$sectoriel <-renderPlot({
sec <- cv_continent %>%
group_by(continent_level) %>%
summarise(total=sum(cases)) %>%
mutate(pourcentage= total/sum(total) * 100)
ggplot(sec, aes(x = "",fill= continent_level)) +
geom_bar(aes(y=pourcentage),width=1,stat="identity")+
coord_polar(theta = "y")+
geom_text(size=1.5,aes(y=pourcentage,label = paste0(round(pourcentage,digits = 2), "%")),
position = position_stack(vjust = 0.5),color="black")+
scale_fill_manual(values = c("Lightblue","#AD7366","Lightgreen","Orange","Coral","#254290"))+
labs(x="",y="",title = "\n",fill= "Libellé de famille de métier")+
theme_classic() + theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 4, color = "#666666"))
})
}
shinyApp(ui=ui, server=server)
这里我想在Continent 部分和第二个tabPanel 名称Diagramme sectoriel 中绘图
如果您需要这里是 csv 和其他文件的链接:https://gitlab.com/Schrodinger168/practice/-/tree/master#
对此的任何帮助将不胜感激!谢谢!
【问题讨论】:
-
plotOutput("image")我没有看到任何地方定义的“图像”。 -
另外,
output$sectoriel <-renderPlot({不会返回任何内容。你需要一个return(sec) -
plotOutput("image")它对我有用,所以我没有放它。我想关注plotOutput("sectoriel") -
啊,好吧,我应该把
return(sec)放在代码末尾的哪里? -
我输入了
return(sec),但它不起作用