我不知道为什么,但我无法将此用于你的示例,而是我自己的小示例。对此表示抱歉。
我删除了目录的检查。想必,你只会这样做一次,并且你会在安装应用程序时这样做。
看来,让它发挥作用的关键在于您应用的CSS样式。闪亮的应用程序在
www
默认情况下为文件夹,因此在样式中指定该选项意味着Shiny无法定位图像。如果您看一下我的示例,我只调用文件名,因为它已经放置在正确的文件夹中。
# Load packages
pkgs <- c("shiny", "ggplot2")
invisible(lapply(pkgs, require, character.only = TRUE))
# Generate a plot
some_plot <- ggplot(mpg, aes(class)) +
geom_bar()
ggsave(
"www/some-plot.png",
some_plot,
device = "png"
)
# Define the user interface
ui <- fluidPage(
div(
style = "height: 550px; width = 550px;
background: url('some-plot.png') no-repeat center center;
background-size: cover;"
)
)
# Define the server side
server <- function(input, output, session) {
}
# Combine into an app
shinyApp(ui = ui, server = server)
我确实删除了文件,重新启动了RStudio并重新运行了应用程序,它能够创建图像并使用CSS样式将其呈现为背景。请对你的代码(修改过的ofc)和我的代码进行同样的尝试。也许我修改了你的代码,做了一些不正确的事情,或者你发现了我遗漏的东西。