user6559913
user6559913

Reputation: 513

How to pass a variable using url to another shiny app in R?

I have one script which plots the graph for any category type say A,B & C ,i am using "textinput" for entering desired category. Now i want to pass this selected category to another script through URL. This script should take that value and do calculations. How can i pass variables from one shiny script to another as input?

Upvotes: 2

Views: 1177

Answers (1)

nilsole
nilsole

Reputation: 1723

Well, there are many different ways for sending data via URL.

This is a very primitive example of a dispatcher app, using HTTP GET via readlines() for sending some tiny data with Shiny to a remote URL.

In this answer, you can read how to parse the data from the query string when creating the receiver app.

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)

Depending on what you want to achieve, if you want to share large amounts of data, it might be better to use a shared database or to use an HTTP POST request instead.

Upvotes: 1

Related Questions