Oli*_*121 5 r image local shiny display
我花了相当多的时间试图解决这个问题。当然,在在这里分享我的问题之前我做了功课。
特别是我咨询过失败:
所以我在 RStudio 项目文件的根目录下创建了一个“www”文件夹,我在其中放置了一些图片。
这些图片在 titlePanel 中使用,但也由应用程序调用的主 htmlwidget 使用。
对我来说,将这些图片存储在本地至关重要,因为应用程序可能在安全的环境中运行,而无需访问互联网。
我尝试了这些图片的相对路径和绝对路径:没有显示图片。
然后我注意到某种不一致:仅当我通过 RStudio 中的常规命令“运行选定行”运行应用程序时,我才会遇到此问题。另一方面,当我通过专用命令“运行应用程序”(在 RStudio 的右上角,绿色箭头)运行应用程序时,我不再遇到这个问题,图片显示得很好(但输入数据是以某种方式进行检查,并且在启动应用程序之前需要花费很多时间)。
最初我认为显示本地图像比显示存储在互联网上的远程图像容易得多,但事实似乎恰恰相反。
因此我的问题是:
此致,
奥利维尔
Run Selected Line(s)对我来说,通过RStudio运行应用程序时,以下操作也适用:
library(shiny)
# create some local images
if(!dir.exists("myimages")){
dir.create("myimages")
}
myPlotPaths <- paste0("myimages/myplot", seq_len(3), ".png")
for (myPlot in myPlotPaths) {
png(file = myPlot, bg = "transparent")
plot(runif(10))
dev.off()
}
myImgResources <- paste0("imgResources/myplot", seq_len(3), ".png")
# Add directory of static resources to Shiny's web server
addResourcePath(prefix = "imgResources", directoryPath = "myimages")
ui <- fluidPage(
tags$img(src = myImgResources[1], width = "400px", height = "400px"),
tags$img(src = myImgResources[2], width = "400px", height = "400px"),
tags$img(src = myImgResources[3], width = "400px", height = "400px")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9616 次 |
| 最近记录: |