我用R用Shiny写了一些代码。但是,无论我在尝试什么,我的pieChart都不会显示。是我的数据还是代码错误?图表的数据如下所示:
值名称
dbl chr
17种
10电影
8电视连续剧6游戏
5食物
46随机
library(shiny)
library(shinydashboard)
library(dplyr)
ui <- dashboardPage(
dashboardHeader(title = "Catnames in Europe"),
skin = "red",
dashboardSidebar(
img(src = "cats_looking.jpg", height = 100, width = 150, align = "left"),
selectInput("countries",
"Choose country:",
choices = c("Netherlands","Germany","Turkey","Ireland",
"England","Belgium","Spain","Portugal",
"United Sates","Denmark","Sweden",
"Switzerland","Italy"),
selected = "Netherlands",
multiple = FALSE,
width = '400px'),
selectInput("years",
"Choose Year:",
choices = c("2017","2018","2019","2020"),
selected = "2019",
multiple = FALSE,
width = '400px'),
actionButton("button","Update view",style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
tags$div(div_id= "distPie", class ="plot-Output")
),
dashboardBody(fluidRow(
tabBox(
tabPanel("Countries",tableOutput("catnametable"),
style = "background-color: #ffffff;")),
tabBox(
tabPanel("Years",tableOutput("years"),
style = "background-color: #ffffff;"),
tabPanel("Trends in 2019",deliverChart(div_id = "pieChart", running_in_shiny = TRUE),
style = "background-color: #ffffff;"))
)))
server <- function(input, output) {
output$catnametable <- renderTable({
countrylist <- CatnamesEurope %>%
filter(Country %in% input$countries)
})
output$years <- renderTable({
yearlist <- Years2 %>%
filter(Years_ordered %in% input$years)
})
output$pieChart <- renderPieChart(
div_id = "pieChart",
data = Trends,
radius = '75%',
center_x = '50%',
center_y = '50%',
show.label = TRUE,
show.legend = TRUE, show.tools = TRUE,
font.size.legend= 12
)
}
shinyApp(ui = ui, server = server)
这里有一些尝试。
output
由于没有您的全部数据,我注释了一些声明。
我还补充说:
loadEChartsLibrary(),
tags$div(id="pieChart", style="width:100%;height:400px;"),
在您打电话之前deliverChart
。
library(shiny)
library(shinydashboard)
library(dplyr)
library(ECharts2Shiny)
Trends <- data.frame(
value = c(17,10,8,6,5,46),
name = c("Species", "Movies", "TV Series", "Games", "Food", "Random"),
stringsAsFactors = FALSE
)
ui <- dashboardPage(
dashboardHeader(title = "Catnames in Europe"),
skin = "red",
dashboardSidebar(
img(src = "cats_looking.jpg", height = 100, width = 150, align = "left"),
selectInput("countries",
"Choose country:",
choices = c("Netherlands","Germany","Turkey","Ireland",
"England","Belgium","Spain","Portugal",
"United Sates","Denmark","Sweden",
"Switzerland","Italy"),
selected = "Netherlands",
multiple = FALSE,
width = '400px'),
selectInput("years",
"Choose Year:",
choices = c("2017","2018","2019","2020"),
selected = "2019",
multiple = FALSE,
width = '400px'),
actionButton("button","Update view",style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
tags$div(div_id= "distPie", class ="plot-Output")
),
dashboardBody(fluidRow(
tabBox(
tabPanel("Countries",tableOutput("catnametable"),
style = "background-color: #ffffff;")),
tabBox(
tabPanel("Years",tableOutput("years"),
style = "background-color: #ffffff;"),
tabPanel("Trends in 2019",
loadEChartsLibrary(),
tags$div(id="pieChart", style="width:100%;height:400px;"),
deliverChart(div_id = "pieChart", running_in_shiny = TRUE),
style = "background-color: #ffffff;"))
)))
server <- function(input, output) {
output$catnametable <- renderTable({
#countrylist <- CatnamesEurope %>%
# filter(Country %in% input$countries)
})
output$years <- renderTable({
#yearlist <- Years2 %>%
# filter(Years_ordered %in% input$years)
})
output$pieChart <- renderPieChart(
div_id = "pieChart",
data = Trends,
radius = '75%',
center_x = '50%',
center_y = '50%',
show.label = TRUE,
show.legend = TRUE, show.tools = TRUE,
font.size.legend= 12
)
}
shinyApp(ui = ui, server = server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句