shiny - Run a app from terminal and send a password
问题描述
I want to launch a shiny application from a terminal to avoid blocking the rstudio console.
My application uses the ssh package to connect to a remote machine.
When I launch the application from rstudio a small window opens to ask me for my password but when I launch the application from the terminal i get an error message.
$ "Rscript.exe" -e "shiny::runApp('app')"
Loading required package: shiny
Warning: package 'shiny' was built under R version 3.5.3
Warning: package 'ssh' was built under R version 3.5.3
Linking to libssh v0.8.6
Password callback did not return a string value
Erreur : Authentication with ssh server failed
Stopped
app.R
library(shiny)
library(ssh)
ssh.session <- ssh::ssh_connect(host = host)
cat("*** Logging in of the session ***")
# Define UI for application that draws a histogram
ui <- fluidPage()
server <- function(input, output) {
onStop(function() {
ssh_disconnect(ssh.session)
cat("*** Logging out of the session ***")
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
我不知道您在用例中的安全必要性...
您可以做的(如果您可以在调用 Rscript 时指定密码)是在调用时将密码作为额外参数提供RScript
,然后将其转发到ssh_connect()
. 您也可以对主机变量执行相同的操作。我通过以下方式调用此 R 文件:
Rscript --vanilla home/user/R/app.R "password"
我没有运行shiny::runApp
,因为线路shinyApp(ui=ui, server=server)
会自动启动闪亮的应用程序,让我们事先连接到 ssh。
在 app.R 文件中,我们将参数转发给 ssh_connect。
应用程序.R
library(shiny)
library(ssh)
args <- commandArgs(trailingOnly = TRUE)
host="host"
ssh.session <- ssh::ssh_connect(host = host,passwd = )
cat("*** Logging in of the session ***")
# Define UI for application that draws a histogram
ui <- fluidPage()
server <- function(input, output) {
onStop(function() {
ssh_disconnect(ssh.session)
cat("*** Logging out of the session ***")
})
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- angular - 如何使用 Angular 应用程序的 highcharts 显示实时数据?
- prolog - 从其他谓词调用时谓词返回 false
- docker - 如何处理“无效的参考格式”
- c# - 实例化一个网络服务,
是一个命名空间,但它被用作一种类型 - mysql - LocalDate 导致数据截断:日期值不正确
- html - 我想在底部页面显示页脚
- php - 在准备好的 SQL LIKE - PHP 中使用通配符 - 或者我的结果是否损坏?
- ruby-on-rails - Rails 多条记录更新
- html - 是否可以使用屏幕阅读器搜索包含某些 aria-label 文本的按钮?
- python - Pandas groupby 累积总和忽略当前行