Detecting open solo mode from shiny app?

Hi all,

Hopefully a quick one:

Any suggestions on how to detect open solo mode from within a shiny app?

I aim to hide a navigation button with shiny::conditionalPanel based on whether it's in open solo or not. I've tried hooking into session$clientData$url_pathname but it doesn't change even when the browser navigation bar path is different for the same document.

I can't see any documented environment variables which I could hook into, though I still need to try an env dump just to be sure.

Any other ideas?

This is a really interesting question!! I know there would be a way to do this by sending data back from the frontend (if it's not already).

I'm curious to hear more about why you are using this though - is this hidden panel something that helps you get back to the "dashboard" view?

This example app can help see the data that is exposed to Shiny by default:

Yes I'm just experimenting at the moment, but the button would navigate to a relative location.href via 'onclick'. Currently it takes users back to the dashboard view, but it's behind a proxy so I could turn that into anything I liked.

The relative href doesn't work within the dashboard view, so I was planning to hide it to prevent obvious errors.

This is a fantastic use case!! Very cool!

I will try to package this up into something more usable within R, but it should be do-able (so long as iframe origin stuff doesn't block it) with window.location.href == window.top.location.href)

https://colorado.rstudio.com/rsc/connect/#/apps/b4ffeb62-3290-4227-829d-799e10bd802b/access

vs.

https://colorado.rstudio.com/rsc/cole/shiny-open-solo/

The source:

(And my reference. Everything starts with an SO post :grinning_face_with_smiling_eyes: )

EDIT: Inline in case links break:

library(shiny)

js_helpers <- "
function is_solo() {
  alert(window.location.href == window.top.location.href)
}
"

ui <- fluidPage(

    titlePanel("Determine if Open Solo"),
    tags$script(HTML(js_helpers)),

    sidebarLayout(
        sidebarPanel(
        ),

        mainPanel(
            htmltools::tags$button(
                "Is this open solo?",
                onclick = "is_solo();"
            )
        )
    )
)

server <- function(input, output) {
}

shinyApp(ui = ui, server = server)
1 Like

Very clever, & nice & simple too.

Many thanks Cole!

:grin:

1 Like

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.