R Studio Connect serving data via url into shiny/htmlwidgets, or how to connect frontend to backend on R Studio connect

Hi,
So I'm trying to get a vitessceR widget running in a shiny app and publish on R Studio Connect (RSC). The app runs and works on the local machine; vitessce can listen and find data files through localhost. However, when published to RSC the widget cannot find the files bundled with it.
Since the visualizations in Vitessce are rendered completely in the browser, the big question in a deployment setting is how to serve data files in a way that the Vitessce frontend can access them (from a browser environment that is not necessarily local to the data files/server). The Vitessce Python and R packages use lightweight web server packages (plumber in R, hypercorn in Python) by default to serve local data on localhost, but this will not work in a deployment setting because localhost is meaningless to remote clients.
The authors of the widget suggest replacing the built-in server for Shiny's addResourcePath. However, I found that this does not work normally on RSC. The minimal code example below does not seem to function on the platform:

library(shiny)

if(!dir.exists("www")){
  dir.create("www")
}

addResourcePath(prefix = "www", directoryPath = "./www")


png(filename = file.path("./www/test.png"))
x <- 1:50
y <- runif(50)
plot(x, y, type = "l")
invisible(dev.off())

ui <- fluidPage(
  tags$img(src = "www/test.png")
)

server <- function(input, output, session) {}

app <- shinyApp(ui, server)

runApp(app)

I've also looked into session$clientData on RSC but the session$clientData$url_pathname and session$clientData$url_search both return 404 errors so I assume they don't work on RSC for security reasons. I'm blocked now trying to figure out how to serve data to this widget on RSC without having to host the data files on another web host.

My question is this : After publishing an app bundle to R Studio Connect, is it possible to serve local data from the app working directory using the RSC web server? If so, is there a url path I should point my frontend code to? If not, does anyone know how can I configure a htmlwidget to read from current working directory instead of looking for a url?

I can elaborate further if my question is unclear.

One potential deployment strategy: the vitessce website illustrates having the widget call data hosted remotely in, for example, an s3 bucket.

I downloaded the data from that bucket, rendered the widget locally with urls pointing to the Connect server,
and then deployed the document and data to the server via an RMarkdown document where the data were listed as resource files. The running example is here. You could deploy the widget and data separately if you wanted.

In the end, that is what I've done. I provisioned an s3 bucket to host the config.json for Vitessce and the related data files. Seems to work with the following caveat. The example on github.io in your post is out of date and some of the json data types are no longer supported in VitessceR, it uses zarr data stores instead. Your running example no longer renders the spatial data as a result.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.