因此,我正在使用
apexcharter
作为图表制作一个闪亮的应用程序,并且我需要制作非常小的直方图(大约 40/60 像素高),这些直方图将包含在具有其他关键统计数据的框中。起初,我使用 spark_box
函数,它允许我快速获得所需大小的最小图形,但边框和阴影使它们以“丑陋”的方式过于突出。
然而,当我尝试简单地切换到这些直方图的
apex
功能时,我注意到显示的图表并未使用可用的完整高度,尽管我禁用了所有标签选项来重新创建 spark_box
。这是它的样子:
有没有办法让
apex
图表占据全部可用空间,甚至有办法禁用spark_box
的边框和阴影?
这是该问题的可重现示例:
### Libraries
library(shiny)
library(bslib)
library(tidyverse)
### Data
myIris <- iris %>% as_tibble() %>% mutate(Species = as.factor(Species)) %>%
summarise(Sepal.Length = mean(Sepal.Length), .by = Species)
### App
server <- function(input, output, session) {
output$spark <- renderSparkBox(spark_box(myIris, type = "column"))
output$chart <- renderApexchart(
apex(data = myIris, mapping = aes(x = Species, y = Sepal.Length)) %>%
ax_legend(show = FALSE) %>%
ax_dataLabels(enabled = FALSE) %>%
ax_yaxis(labels = list(show = FALSE)) %>%
ax_xaxis(labels = list(show = FALSE, style = list(fontSize = "12px", fontWeight = 10)),
axisBorder = list(show = FALSE), axisTicks = list(show = FALSE)) %>%
ax_grid(yaxis = list(lines = list(show = FALSE)),
xaxis = list(lines = list(show = FALSE))) %>%
ax_chart(toolbar = TRUE)
)
session$onSessionEnded(function() {stopApp()})
}
ui <- page_fluid(
div(class = "content",
div(class = "container-xl",
card_body("This is the spark box (height = 60px)",
sparkBoxOutput("spark", height = "60px")),
card_body("This is the apex chart (height = 60px)",
apexchartOutput("chart", height = "60px"))
)))
shinyApp(ui, server)
我找到了允许我完全按照我所描述的操作的参数。我可以使用
ax_[...]()
的 sparkline 参数,而不是使用顶点图表模拟 Spark_box 的所有 ax_chart()
函数,如下所示:
ax_chart(sparkline = list(enabled = TRUE))
这给了我这个:
这是完整的更正代码:
### Libraries
library(shiny)
library(bslib)
library(tidyverse)
### Data
myIris <- iris %>% as_tibble() %>% mutate(Species = as.factor(Species)) %>%
summarise(Sepal.Length = mean(Sepal.Length), .by = Species)
### App
server <- function(input, output, session) {
output$spark <- renderSparkBox(spark_box(myIris, type = "column"))
output$chart <- renderApexchart(
apex(data = myIris, mapping = aes(x = Species, y = Sepal.Length)) %>%
ax_chart(sparkline = list(enabled = TRUE))
)
session$onSessionEnded(function() {stopApp()})
}
ui <- page_fluid(
div(class = "content",
div(class = "container-xl",
card_body("This is the spark box (height = 60px)",
sparkBoxOutput("spark", height = "60px")),
card_body("This is the apex chart (height = 60px)",
apexchartOutput("chart", height = "60px"))
)))
shinyApp(ui, server)