簡體   English   中英

有沒有辦法通過 GET 請求 Shiny 應用程序?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM