如何在 ubuntu 服务器上安装 R 和 shiny 包并在不启动浏览器的情况下将其发布到 shiny-server
How install R and shiny package on ubuntu server and publish it on shiny-server without launching browser
我是 R 和 Shiny 应用程序的新手,所以如果这个问题看起来有点愚蠢,请接受我的道歉。
所以,基本上我想要的是自动化一个闪亮的应用程序仪表板,目前我正在从我的 windows 机器上 运行ning。
我从数据库中获取每小时数据并将文件保存在 R 的工作目录中。
我遵循的步骤:
- 打开 R 工作室
- 运行 我的闪亮应用程序,它在我的本地主机 'http://127.0.0.1:7790/'
上生成了一个仪表板
- 我点击它右上角的按钮调用 "Publish" 将我的仪表板发布到闪亮的服务器“https://www.shinyapps.io”
现在我 运行 这个过程几乎每小时都手动进行。我的 Apache Airflow 运行ning 在我的 ubuntu 服务器之一上。
所以,我愿意在我的 ubuntu 服务器上安装 R, Shiny 软件包,并希望从那里调用闪亮的应用程序并在闪亮的服务器上发布我的仪表板。
一旦我能够从命令行调用它,那么我认为其余的事情将很容易在我的 Airflow 工具上按小时安排 运行。
显然,我不想在 shiny 服务器上发布我的 shinyApp 时启动浏览器。
这方面的任何帮助都会对我有很大帮助。提前致谢。
所以我找到了一个解决方案,可以从我的 ubuntu 服务器自动化我闪亮的应用程序。
我的 Apache Airflow 工具已经在 AWS 的 Ubuntu 服务器上启动并 运行ning。
假设你想从服务器部署它,请 运行 下面的命令来安装 R-base 和依赖项:
sudo su -c "echo 'deb http://archive.linux.duke.edu/cran/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get install r-base -y
sudo su --c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('fpp', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('rmarkdown', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('ggplot2', repos='https://cran.rstudio.com/')\""
sudo apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
Post成功安装R、Shiny和所需的包,我们将检查R是否安装成功(您将看到如下交互式R终端):
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
运行 下面来自 R 终端的命令安装依赖项和 rsconnect 包:
install.packages('devtools')
install.packages('rsconnect')
键入 'q()' 退出 R 终端。
现在我们需要在我们的 sudo 命令中设置 R 中的工作目录,以在 shinyapps.io 网络服务器上部署仪表板。在 运行 命令之前确保你已经在 R 中添加了令牌。你可以查看它或者可以参考下面的 link:
https://shiny.rstudio.com/articles/shinyapps.html
现在 运行 下面的命令在 shinyapps.io 上部署应用程序:
sudo -i R -e "rsconnect::deployApp(appDir = '/your/ubuntu/Directory_Path', launch.browser = FALSE, forceUpdate = TRUE)"
我是 R 和 Shiny 应用程序的新手,所以如果这个问题看起来有点愚蠢,请接受我的道歉。 所以,基本上我想要的是自动化一个闪亮的应用程序仪表板,目前我正在从我的 windows 机器上 运行ning。 我从数据库中获取每小时数据并将文件保存在 R 的工作目录中。
我遵循的步骤:
- 打开 R 工作室
- 运行 我的闪亮应用程序,它在我的本地主机 'http://127.0.0.1:7790/' 上生成了一个仪表板
- 我点击它右上角的按钮调用 "Publish" 将我的仪表板发布到闪亮的服务器“https://www.shinyapps.io”
现在我 运行 这个过程几乎每小时都手动进行。我的 Apache Airflow 运行ning 在我的 ubuntu 服务器之一上。
所以,我愿意在我的 ubuntu 服务器上安装 R, Shiny 软件包,并希望从那里调用闪亮的应用程序并在闪亮的服务器上发布我的仪表板。 一旦我能够从命令行调用它,那么我认为其余的事情将很容易在我的 Airflow 工具上按小时安排 运行。
显然,我不想在 shiny 服务器上发布我的 shinyApp 时启动浏览器。
这方面的任何帮助都会对我有很大帮助。提前致谢。
所以我找到了一个解决方案,可以从我的 ubuntu 服务器自动化我闪亮的应用程序。 我的 Apache Airflow 工具已经在 AWS 的 Ubuntu 服务器上启动并 运行ning。 假设你想从服务器部署它,请 运行 下面的命令来安装 R-base 和依赖项:
sudo su -c "echo 'deb http://archive.linux.duke.edu/cran/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get install r-base -y
sudo su --c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('fpp', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('rmarkdown', repos='https://cran.rstudio.com/')\""
sudo su --c "R -e \"install.packages('ggplot2', repos='https://cran.rstudio.com/')\""
sudo apt-get install build-essential libcurl4-gnutls-dev libxml2-dev libssl-dev
Post成功安装R、Shiny和所需的包,我们将检查R是否安装成功(您将看到如下交互式R终端):
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
运行 下面来自 R 终端的命令安装依赖项和 rsconnect 包:
install.packages('devtools')
install.packages('rsconnect')
键入 'q()' 退出 R 终端。 现在我们需要在我们的 sudo 命令中设置 R 中的工作目录,以在 shinyapps.io 网络服务器上部署仪表板。在 运行 命令之前确保你已经在 R 中添加了令牌。你可以查看它或者可以参考下面的 link:
https://shiny.rstudio.com/articles/shinyapps.html
现在 运行 下面的命令在 shinyapps.io 上部署应用程序:
sudo -i R -e "rsconnect::deployApp(appDir = '/your/ubuntu/Directory_Path', launch.browser = FALSE, forceUpdate = TRUE)"