Open thebioengineer opened 10 months ago
shouldn't
session$clientData
be
parseQueryString(session$clientData$url_search)
yes, for the specific problem posed. So it probably would have been better to have the example include that.
Admittedly, I got distracted while constructing the example and saw that session$clientData
does have a fair amount of information that is lost on deployment via shinylive that folks might want.
@thebioengineer no worries was just mentioning in case that was the issue. I'm equally curious about parsing query parameters. Glad you asked the question.
Oooooooo! I think I got this one haha.
The issue comes from the app being run in an iframe. The query string / hash are not being forwarded.
Smaller app that shows all information in the JS console:
library(shiny)
ui <- fluidPage(verbatimTextOutput("search_values"))
server <- function(input, output, session) {
observe({
str(reactiveValuesToList(session$clientData))
})
output$search_values <- renderText({
invalidateLater(1000)
paste(capture.output({
print(Sys.time())
str(getQueryString())
}), collapse = "\n")
})
}
shinyApp(ui, server)
While at url http://127.0.0.1:1234/?barret=1#asdf
I had JS console messages:
preload echo:List of 10
shinylive.js:34937 preload echo: $ output_search_values_hidden: logi FALSE
shinylive.js:34937 preload echo: $ pixelratio : num 1.5
shinylive.js:34937 preload echo: $ url_protocol : chr "http:"
shinylive.js:34937 preload echo: $ url_hostname : chr "127.0.0.1"
shinylive.js:34937 preload echo: $ url_port : chr "1234"
shinylive.js:34937 preload echo: $ url_pathname : chr "/app_u02o4jrgxutrye5cu93x/"
shinylive.js:34937 preload echo: $ url_search : chr ""
shinylive.js:34937 preload echo: $ url_hash_initial : chr ""
shinylive.js:34937 preload echo: $ url_hash : chr ""
shinylive.js:34937 preload echo: $ singletons : chr ""
If I updated the iframe's src
attr to be /app_u02o4jrgxutrye5cu93x/?barret=1#asdf
, I had the JS console message:
preload echo:List of 10
shinylive.js:34937 preload echo: $ output_search_values_hidden: logi FALSE
shinylive.js:34937 preload echo: $ pixelratio : num 1.5
shinylive.js:34937 preload echo: $ url_protocol : chr "http:"
shinylive.js:34937 preload echo: $ url_hostname : chr "127.0.0.1"
shinylive.js:34937 preload echo: $ url_port : chr "1234"
shinylive.js:34937 preload echo: $ url_pathname : chr "/app_u02o4jrgxutrye5cu93x/"
shinylive.js:34937 preload echo: $ url_search : chr "?barret=1"
shinylive.js:34937 preload echo: $ url_hash_initial : chr "#asdf"
shinylive.js:34937 preload echo: $ url_hash : chr "#asdf"
shinylive.js:34937 preload echo: $ singletons : chr ""
🎉
Will make a PR in shinylive
Amazing! Many thanks for looking into this.. hopefully it was an interesting one.
George beat me by two weeks 🤣
We will wait on posit-dev/shinylive#79 .
So I imagine I should be able to pass this by just running either of the below?
options(passUrlParams = TRUE)
shiny::shinyApp(ui = ui, server = server, options = list(passUrlParams = TRUE))
I have an app from my screencast that I tried to turn into a shinylive app that takes advantage of session$clientData$url_search to pull in the query params from a user. Once I used shinylive to convert it, the queries passed to the URL did get passed onto the shinylive shiny session.
Not sure how large of use-case this is, but I would imagine some folks might want bookmarking to function so flagging for your attention.