【问题标题】:How to pass a variable using url to another shiny app in R?如何使用 url 将变量传递给 R 中另一个闪亮的应用程序?
【发布时间】:2017-02-21 10:34:27
【问题描述】:

我有一个脚本可以绘制任何类别类型的图形,例如 A、B 和 C,我正在使用“textinput”来输入所需的类别。现在我想通过 URL 将这个选定的类别传递给另一个脚本。该脚本应采用该值并进行计算。如何将变量从一个闪亮的脚本传递到另一个作为输入?

【问题讨论】:

    标签: html r shiny-server


    【解决方案1】:

    嗯,通过 URL 发送数据有很多不同的方法。

    这是一个非常原始的调度程序应用示例,通过readlines() 使用 HTTP GET 将一些带有 Shiny 的微小数据发送到远程 URL。

    In this answer,您可以在创建接收应用程序时阅读如何从查询字符串中解析数据。

    library(shiny)
    
    dataToBeSent <- list(
      "someVariable" = "myValue",
      "anotherVariable" = "anotherValue"
    )
    
    ui <- shinyUI(
      titlePanel("Simply sending some data via HTTP GET")
    )
    
    server <- shinyServer(function(input, output, session) {
      sendData <- function ( listData, url ){
        print("Server says: Let's pass data to a remote url!")
        url <- paste0( url,"?",paste(paste( names(listData),unname(listData),sep="=" ),collapse="&"))
        readLines(URLencode(url))
      }
      sendData( dataToBeSent, "http://www.example.com/shinyApp/"  )
    })
    
    shinyApp(ui = ui, server = server)
    

    根据您想要实现的目标,如果您想共享大量数据,最好使用共享数据库或use an HTTP POST request

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      相关资源
      最近更新 更多