![](/img/trans.png)
[英]Make a Shiny app execute code when called via HTTP GET (e.g. cURL)
[英]Is there a way to request a Shiny app via GET?
我想通過 GET 請求執行 Shiny 應用程序,即當最初通過瀏覽器調用 Shiny 應用程序時觸發的所有腳本都應由 GET 請求執行。 有沒有好的方法來處理這個?
我可以用httr
package 解決這個問題嗎?
例子
library(httr)
GET("link_to_a_shiny_app")
這可以通過管道工完成( httr
可以在客戶端使用)。
下面創建管道工 API,它在后台 R 進程中運行 shiny 應用程序,並在port
端點被訪問后返回 shiny 應用程序的相應端口:
library(plumber)
library(shiny)
library(httpuv)
library(callr)
#* @apiTitle Shiny runApp API
#* @apiDescription runs a shiny app and returns the port.
#* Echo back the input
#* @param port The shiny app port
#* @get /port
function() {
ui <- fluidPage(
h1("This is a test app")
)
server <- function(input, output, session) {}
app <- shinyApp(ui, server)
port <- httpuv::randomPort()
r_bg(function(app, port){
shiny::runApp(appDir = app,
port = port,
launch.browser = FALSE,
host = "0.0.0.0")
}, args = list(app = app, port = port), supervise = TRUE)
port
}
# plumb(file='plumber.R')$run()
# http://127.0.0.1:6107/port
另請參閱此處關於如何使用 shiny 應用程序直接處理 http 動詞的回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.