在 ioslides_presentation 中使用 dyn.load 时出错 w/runtime: shiny

Error using dyn.load in ioslides_presentation w/ runtime: shiny

一位同事将数千个 S 函数和 Fortran 子例程移植到 R。原生 R 函数包含在 5 个 .RData 文件中,Fortran 子例程包含在 2 个 .dll 文件中。

为了使我的文档更便携,这些文件已上传到 Blackboard 并使用

加载到 R 中
---
title: "dyn.load and Shiny"
subtitle: "Why can't we all just get along?"
author: "Jason Freels"
output:
  ioslides_presentation:
    widescreen: true
runtime: shiny
---

```{r echo=FALSE,message=FALSE}
setInternet2(TRUE)

download.file("http://afit.blackboard.com/bbcswebdav/users/jfreels/DFORRT.dll",
          paste(c(getwd(),"/DFORRT.dll"), collapse=""),
          method="internal",mode="ab")

dyn.load("DFORRT.dll")

download.file("http://afit.blackboard.com/bbcswebdav/users/jfreels/SPLIDA.dll",
          paste(c(getwd(),"/SPLIDA.dll"), collapse=""),
          method="internal",mode="ab")

dyn.load("SPLIDA.dll")

a<-url("https://afit.blackboard.com/bbcswebdav/users/jfreels/echapters.RData"    ); load(a)
b<-url("https://afit.blackboard.com/bbcswebdav/users/jfreels/RSplida Codes.RData"); load(b)
c<-url("https://afit.blackboard.com/bbcswebdav/users/jfreels/RSplidaData.RData"  ); load(c)
d<-url("https://afit.blackboard.com/bbcswebdav/users/jfreels/RSplidaUser.RData"  ); load(d)
e<-url("https://afit.blackboard.com/bbcswebdav/users/jfreels/Text data.RData"    ); load(e)
```

此代码非常适合 pdf_document、html_document 和 ioslides_presentation 参数,当我添加 runtime: shiny 时,我可以在 RStudio 中成功生成演示文稿的预览观众。但是,当我尝试将演示文稿部署到 shinyapps.io 时,出现错误:"unable to find function setInternet2"

之前,我尝试使用

在本地加载 .dll 文件
for (i in 1:2){ dyn.load(list.files(getwd())[grep("dll",strsplit(list.files(getwd()),"\W+"))][i]) } 

使用这种方法,我也可以在 RStudio 中成功生成预览,但是当我尝试部署演示文稿时,我收到一个不同的错误,指出加载共享库的尝试导致 "invalid ELF header."

闪亮(或 shinyapps.io)和 .dll 文件之间是否存在冲突?

提前致谢,

贾森

也许文档中没有说清楚,但是ShinyApps.io使用了Linux个实例(Ubuntu),所以你肯定不能加载.dll文件(Windows-只有那里。最自然和便携的解决方案是将其制作为 R 包,将其放在 Github 上,使用 devtools::install_github() 安装它,然后将应用程序部署到 ShinyApps.io。然后软件包将在 Linux 上重新安装和编译,您无需关心您的 Fortran 代码是否变为 .dll.so 或其他。

如果你真的不愿意做一个R包(这其实很容易做而且有巨大的好处),你当然可以调用R CMD SHLIB来编译你的Fortran代码,但你不应该硬-将扩展名编码为 .dll。根据您的平台,它可能会有所不同:请改用 .Platform$dynlib.ext