如何在 R 包中包含和显示图像?

问题描述

我正在尝试打包一个 Shiny 模块,该模块显示带有徽标的模式(以 png 格式)。为此,我创建了一个“inst/www”目录来存储徽标文件。目录树看起来像这样:

├─ DESCRIPTION
├─ inst
│   └── www
│       └── logo.png
├── man
│   └── test.Rd
├── NAMESPACE
├── packagetest.Rproj
└── R
    └── test.R

但是,在构建和安装之后,该包似乎没有从我放置“logo.png”的预定义目录中读取。相反,它从我从包中插入函数的主项目中读取。包的 testUI() 函数是这样的:

testUI <- function(id) {
  ns <- NS(id)

  shiny::showModal(
    modalDialog(
      title = img(src="inst/www/logo.png",style="display:block; margin-left:auto; margin-right:auto;"),br(),fluidRow(
        column(6,align="center",offset = 3,textInput(ns("username"),label = NULL,placeholder = "Username"),passwordInput(ns("password"),placeholder = "Password")
        )
      ),footer = (
        fluidRow(
          column(6,actionButton(ns("signin"),"Sign in")
          )
        )
      )
    )
  )
}

从我在其他项目中看到的情况来看,“inst”文件夹似乎是要走的路,但我还是 R 包的新手,所以我真的不知道我在做什么。非常感谢您对此的任何帮助,谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)