4

I have packaged a Shiny application as a Windows desktop App by following the following tutorial: http://www.r-bloggers.com/deploying-desktop-apps-with-r/

In my Shiny application I provide the user to generate a PDF Report using pandoc and MikTex. In order for this to work in my Desktop application, I have added the following code in my runShinyApp.R script.

Sys.setenv(PATH=paste("C:/Users/WoBa/Documents/dist/pandoc",sep=";",
"C:/Users/WoBa/Documents/dist/miktex/miktex/bin/"))

Although this works correctly, I would like this path to be relative so the application can be distributed to other users without them having to change the path.

I've tried the following - but this didn't work:

Sys.setenv(PATH=paste("./pandoc",sep=";",
"./miktex/miktex/bin/"))

Folder structure is the following:

dist/
 + GoogleChromePortable
 + miktex
 + pandoc
 + R-Portable
 + runShinyApp.R
 + run.bat

Anybody maybe nows how to make this path relative? (on Windows) It would help me a lot!

4

2 回答 2

2

我设法在我的 runShinyApp.R 脚本中使用以下代码提供了一个相对路径:

miktex = file.path(getwd(), 'miktex/miktex/bin/')
pandoc = file.path(getwd(), 'pandoc')

Sys.setenv(PATH=paste(pandoc, sep=";", miktex))

只需提供答案,因为这可能对其未来的其他人有用。

于 2016-01-14T09:06:06.610 回答
1

我使用相同的教程制作了一个类似的应用程序。我已根据 ny Yihui Xie提供的解决方案将以下内容添加到我的 runShinyApp.R 脚本中,jst 在 runApp 命令之前。

pandoc <- paste(getwd(), "pandoc-2.4", sep = "/")
TinyTex <- paste(getwd(), "TinyTeX/bin/win32", sep = "/")

add_path = function(path) {
  s = .Platform$path.sep
  paths = c(path, unlist(strsplit(Sys.getenv('PATH'), s)))
  Sys.setenv(PATH = paste(paths, collapse = s))
}

add_path(pandoc)
add_path(TinyTex)
于 2018-11-29T11:39:53.767 回答