饼图以及 infoBox() 闪亮的 App 数据框错误
piechart along with infoBox() shinyApp dataframe error
我想根据 infoBox() 中显示的数据渲染饼图。 shinyApp 应该在信息框中显示结果以及饼图。
这是我的代码:
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
a <- 10
b <- 20
dat1 <- data.frame(a,b)
colnames(dat1) <- c("Male", "Female")
c <- 20
d <- 20
dat2 <- data.frame(c,d)
colnames(dat2) <- c("Male", "Female")
e <- 30
f <- 20
dat3 <- data.frame(e,f)
colnames(dat3) <- c("Male", "Female")
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(
fluidRow(radioButtons("Ben", "Details", c("1","2", "3"), inline = T),
infoBoxOutput("loc", width = 960)
)))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "1"){
box(h3("1"),
infoBox("Total", 30, "Visits", icon = icon('users'), width = 4),
infoBox("M", 10 ,"Visits", icon = icon('male'), width = 4),
infoBox("F", 20 ,"Visits", icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test1", style="width:60%;height:300px;"),
deliverChart(div_id = "test1"), width = "800px", height = "400px",
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
}
else {if (input$Ben == "2") {
box(h3("2"),
infoBox("Total", 40, "Visits", icon = icon('users'), width = 4),
infoBox("M", 20 ,"Visits", icon = icon('male'), width = 4),
infoBox("F", 20 ,"Visits", icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test2", style="width:60%;height:300px;"),
deliverChart(div_id = "test2"), width = "800px", height = "400px",
renderPieChart(div_id = "test2", data = dat2, show.label = TRUE),
background = "black")
}
else{
box(h3("3"),
infoBox("Total", 50 , icon = icon('users'), width = 4),
infoBox("m", 30, icon = icon("male"), width = 4),
infoBox("f", 20, icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test3", style="width:60%;height:300px;"),
deliverChart(div_id = "test3"), width = "800px", height = "400px",
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE), background ="black")
}} }}}
})
})
shinyApp(ui,server)
当 select 单选按钮时,infoBox() 和相关的 饼图 应该显示在 shinyApp .
有人可以帮忙吗?
我认为问题出在 renderPieChart
语句中:
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE)
用于饼图的数据不是 renderPieChart
所需的格式。正在提供 data.frame
,但格式应为:
If it's a data.frame, the data must be made up of only two columns,
"name" and "value". The "value" column must be numeric or integer.
因此,对于 dat1
(和其他数据),您可以执行以下操作(对于 10 名男性,20 名女性):
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
然后它应该绘制饼图。
另请注意,我怀疑第三个饼图应该有div_id = "test 3"
。
我想根据 infoBox() 中显示的数据渲染饼图。 shinyApp 应该在信息框中显示结果以及饼图。
这是我的代码:
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
a <- 10
b <- 20
dat1 <- data.frame(a,b)
colnames(dat1) <- c("Male", "Female")
c <- 20
d <- 20
dat2 <- data.frame(c,d)
colnames(dat2) <- c("Male", "Female")
e <- 30
f <- 20
dat3 <- data.frame(e,f)
colnames(dat3) <- c("Male", "Female")
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(
fluidRow(radioButtons("Ben", "Details", c("1","2", "3"), inline = T),
infoBoxOutput("loc", width = 960)
)))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "1"){
box(h3("1"),
infoBox("Total", 30, "Visits", icon = icon('users'), width = 4),
infoBox("M", 10 ,"Visits", icon = icon('male'), width = 4),
infoBox("F", 20 ,"Visits", icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test1", style="width:60%;height:300px;"),
deliverChart(div_id = "test1"), width = "800px", height = "400px",
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
}
else {if (input$Ben == "2") {
box(h3("2"),
infoBox("Total", 40, "Visits", icon = icon('users'), width = 4),
infoBox("M", 20 ,"Visits", icon = icon('male'), width = 4),
infoBox("F", 20 ,"Visits", icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test2", style="width:60%;height:300px;"),
deliverChart(div_id = "test2"), width = "800px", height = "400px",
renderPieChart(div_id = "test2", data = dat2, show.label = TRUE),
background = "black")
}
else{
box(h3("3"),
infoBox("Total", 50 , icon = icon('users'), width = 4),
infoBox("m", 30, icon = icon("male"), width = 4),
infoBox("f", 20, icon = icon('female'), width = 4),
loadEChartsLibrary(), tags$div(id="test3", style="width:60%;height:300px;"),
deliverChart(div_id = "test3"), width = "800px", height = "400px",
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE), background ="black")
}} }}}
})
})
shinyApp(ui,server)
当 select 单选按钮时,infoBox() 和相关的 饼图 应该显示在 shinyApp . 有人可以帮忙吗?
我认为问题出在 renderPieChart
语句中:
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE)
用于饼图的数据不是 renderPieChart
所需的格式。正在提供 data.frame
,但格式应为:
If it's a data.frame, the data must be made up of only two columns, "name" and "value". The "value" column must be numeric or integer.
因此,对于 dat1
(和其他数据),您可以执行以下操作(对于 10 名男性,20 名女性):
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
然后它应该绘制饼图。
另请注意,我怀疑第三个饼图应该有div_id = "test 3"
。