I'm using a UI function, like so:
ui <- function(req) {
# Some short-circuiting checks here.
# Everything good, let's return the app.
shiny::htmlTemplate(
text_ = some_html,
document_ = TRUE,
named,
template,
variables,
here
)
}
This works great: it returns the UI, Shiny front-end libraries, etc. to the client, which then initiates the websocket request (handled by Shiny's server() function). ![]()
BUT, now I need to add a custom HTTP header to this response, and it doesn't appear that this is doable (at least not directly), so I figured I'd ask here ![]()
When returning a non-Shiny response (i.e. a static page) from the UI function, this is straight-forward:
ui <- function(req) {
if (some_condition) {
return(shiny::httpResponse(
status = 403L,
content_type = "text/html; charset=utf-8",
content = "No soup for you!",
headers = list("x-my-custom-header" = some_dynamic_value)
))
}
}
So, naturally(?) I tried to combine the two and pass the shiny::htmlTemplate() object as the content argument in a similar response, like:
return(shiny::httpResponse(shiny::htmlTemplate(
status = 200L,
content_type = "text/html; charset=utf-8",
content = shiny::htmlTemplate(
text_ = some_html,
document_ = TRUE,
named,
template,
variables,
here
),
headers = list("x-my-custom-header" = some_dynamic_value)
)))
This does not work
.
Has anyone here ever done this (i.e. added a header to the initial, non-websocket, request)?