我有一个
shiny
应用程序,我正在尝试将一些绘图更新为 slickR.
我得到了一些意想不到的效果:
card_footer
消失。sidebar
时,如何保持原始高度和宽度并使其调整大小,就像我只是plotOutput
一样?library(shiny)
library(slickR)
library(svglite)
library(tidyverse)
library(gdtools)
library(bslib)
library(shinyWidgets)
ui <-
page_fluid(layout_sidebar(
sidebar = tagList(
pickerInput("select_a", "Select", choices = LETTERS[1:10]),
pickerInput("select_b", "Select", choices = LETTERS[1:10]),
pickerInput("select_c", "Select", choices = LETTERS[1:10]),
pickerInput("select_d", "Select", choices = LETTERS[1:10])
) ,
bslib::accordion(open = FALSE, accordion_panel("Ab Panel", actionButton("run", "Run"))),
#plotOutput("plt"), slickROutput("slickr"), card_footer(card_body( layout_column_wrap( width = 1 / 2, actionButton("ab1", "Go1"), actionButton("ab2", "Go2") ) ))
))
server <-
function(input, output, session) {
output$plt <-
renderPlot({
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
})
output$slickr <-
renderSlickR({
slickR(svglite::xmlSVG({
methods::show(ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point())
}, standalone = TRUE))
})
}
shinyApp(ui, server)
输入不会被删除,而是简单地隐藏在默认为 7 x 7 英寸的 svg 下方。假设 DPI 为 96,这超出了
slickROutput
的默认高度 (400px)。
因此,您需要告诉
xmlSVG
使用合适的尺寸并使它们与输出的高度同步:
library(shiny)
library(slickR)
library(svglite)
library(tidyverse)
library(gdtools)
library(bslib)
library(shinyWidgets)
p2i <- function(pixels, dpi = 96) {
pixels / dpi
}
height <- 400
ui <-
page_fluid(layout_sidebar(
sidebar = tagList(
pickerInput("select_a", "Select", choices = LETTERS[1:10]),
pickerInput("select_b", "Select", choices = LETTERS[1:10]),
pickerInput("select_c", "Select", choices = LETTERS[1:10]),
pickerInput("select_d", "Select", choices = LETTERS[1:10])
) ,
bslib::accordion(open = FALSE, accordion_panel("Ab Panel", actionButton("run", "Run"))),
slickROutput("slickr", height = height),
card_footer(
card_body(
layout_column_wrap(width = 1 / 2,
actionButton("ab1", "Go1"),
actionButton("ab2", "Go2")
)
)
)
)
)
server <-
function(input, output, session) {
output$slickr <-
renderSlickR({
plt <- svglite::xmlSVG({
show(
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
)
}, height = p2i(height), width = p2i(height), standalone = TRUE)
slickR(
list(plt, plt)
)
})
}
shinyApp(ui, server)