Page redirection fails for rstudio server
Closed this issue · 2 comments
Thanks for a great package, it really has potential I think.
Here is my problem:
If you start a brochure app in "Rstudio server" not "Rstudio"! , you first get a pop up window, I think this window will never work with redirections, but what should work is if you click "open in browser" in this window
Then you get paths, but your app is not running in relative href directory "/" as in normal Rstudio, but something like:
http://localhost:20002/p/adfae814/
So if you redirect to homepage "/", that will make you go to Rstudio server IDE and not the home page of the app.
Because http://localhost:20002/ is the URL for your ssh Rstudio server connection
I guess this is only a bug during development?
To recreate the bug, run Rstudio server on a ssh server and run your example code under redirect section:
brochureApp(
# Pages
page_1(),
page_2(),
page_contact(),
# Redirections
redirect(
from = "/page3",
to = "/page2"
),
redirect(
from = "/page4",
to = "/"
)
)
This will not work.
To fix this I believe there is a way,
Lets say we have a page called "/heatmap", you can manually in the browser update URL to:
http://localhost:20002/p/adfae814/heatmap instead of the failed redirect: http://localhost:20002/heatmap
But then redirection by click will still not work, and if you set the href of each page brochure will fail since it requires a page at location
"/" (This you set as a requirement to make sure there is a home startup page).
To initially fix this you can make a dummy front page that has "/", and have another for redirection later, that will actually work.
What I then need to do is to extract unique client URL, with
observe({
print(reactiveValuesToList(session$clientData))
})
But I have not figured out a way to retrieve this client value and store it to the href of the pages before I actually call the app pages.
Will update here if I figure it out,
Let me know if I am doing something too complicated here :)
Solved it, what you do to make it work on all systems is this:
This minimal example should work to just run:
library(shiny); library(brochure)
metadata_page <- function(nav_links) {
page(
href = "/metadata",
ui <- function(request) {
fluidPage(titlePanel("Metadata search page"), nav_links)
},
server <- function(input, output, session) {}
)
}
landing_page_test <- function(nav_links) {
page(
href = "/",
ui = function(request) {
fluidPage(h1("Welcome"), nav_links)},
server = function(input, output, session) {}
)
}
test_app <- function() {
# Use . for home and no / for metadata
nav_links <- tags$ul(
tags$li(tags$a(href = ".", "home"),),
tags$li(tags$a(href = "metadata", "metadata"),)
)
brochureApp(
options = list(launch.browser = T),
## Pages
# Main menu
landing_page_test(nav_links),
metadata_page(nav_links)
)
}
test_app()
I would maybe add a small section about this in the readme, but for now I will close the issue. Others can just read this issue too.