运行 rize 时包“rJava”的配置失败 - R

configuration failed for package ‘rJava’ when running rize - R

我正在尝试使用 rize 包为 ShinyApp 创建 Dockerfile。从 App 目录启动 rize::shiny_dockerize() 命令。所需的软件包之一是 xlsx(可能还尝试安装 rJava)。我收到以下错误:

trying URL 'https://cran.rstudio.com/src/contrib/xlsxjars_0.6.1.tar.gz'
Content type 'application/x-gzip' length 9477071 bytes (9.0 MB)
==================================================
downloaded 9.0 MB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works... ./configure: line 3766: /usr/bin/java: No such file or directory
no
configure: error: Java interpreter '/usr/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/usr/local/lib/R/site-library/rJava’
Error in i.p(...) :
  (converted from warning) installation of package ‘rJava’ had non-zero exit status
Calls: <Anonymous> ... with_rprofile_user -> with_envvar -> force -> force -> i.p
Execution halted
The command '/bin/sh -c R -e "setwd('/srv/shiny-server/app'); automagic::automagic()"' returned a non-zero code: 1
Error in rize::shiny_dockerize() : object 'view_app' not found

有人知道我如何才能在 rize 包中使用它吗?

rJava 需要一些时间来安装,而且实际上是一个给我带来很多问题的软件包。以下是过去对我有用的方法。

  1. 安装 JAVA JDK 来自:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  2. 在命令行中 运行 : sudo R CMD javareconf

  3. 如果未安装 rJava 库,(这个特定版本适用于我,但您可以尝试安装最新版本)

devtools::install_version("rJava", version = "0.9-9", repos = "http://cran.us.r-project.org")

  1. 重新启动 R 并尝试重新加载 xlsx 包

注意:很多关于这个主题的 Whosebug 问题都建议人们改变环境变量。这对我个人来说并不重要。 sudo R CMD javareconf 应该处理这个问题。

您似乎无法正确设置 Java 的位置。请注意,让 RJava 感到满意可能有点困难。

在此处查看:http://www.owsiak.org/r-java-11-and-making-sure-you-can-load-rjava/ 示例。它基于 macOS,但仍然可以正常工作。

基本上,您要做的是将 JAVA_HOME 设置为指向 Java 安装。完成后,您可以 运行 R cmd javareconf 像这样

> sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME}/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar

确保您已安装 gcc 并且可以编译简单的 C 代码。