1

I am using shinymanager to login a shiny app. Thanks to the this question, I am able to make the page fullscreen by adding an action button on my shiny app. However, I want the app to be fullscreen automatically after logging on the app.

I tried to use observeEvent() wrt the user authentication as below;

auth  <- secure_server( check_credentials = check_credentials(".\\cr\\db.sqlite"))
creds_reactive <- reactive({  auth$user  })

observeEvent(  auth$user, {

        source(".\\funcs\\myfun.R", local = TRUE)  # this works

        js$toggleFullScreen()  # not working

  })

I am able to trigger a sourced function by using auth$user in observeEvent(), but the fullscreen function is not working.

However, I can trigger the very same function at the server side by clicking a button as below.

# Server side
     onclick("my_full_screen_button", {
          js$toggleFullScreen()  # this works
    
        })

# Ui side
 tags$li(id="tam",class = "dropdown", 
    actionButton(icon = icon("expand-arrows-alt"), 'my_full_screen_button','',style="color: #fff; background-color: #888888; border-color: #888888") ),

    

I am suspecting that it stems from the jsToggleFS. But I have almost no knowledge about JS.

Thank you in advance.

maydin
  • 3,715
  • 3
  • 10
  • 27

1 Answers1

0

I would try something like this

library(shiny)
library(shinyjs)

js <- "
function openFullscreen(elem) {
  if (elem.requestFullscreen) {
    elem.requestFullscreen();
  } else if (elem.mozRequestFullScreen) { /* Firefox */
    elem.mozRequestFullScreen();
  } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
    elem.webkitRequestFullscreen();
  } else if (elem.msRequestFullscreen) { /* IE/Edge */
    elem.msRequestFullscreen();
  }
}"

ui <- fluidPage(
  tags$head(
    tags$script(HTML(js))
  ),
  useShinyjs(),
  ......

And in server:

observeEvent(auth$user, {

  source(".\\funcs\\myfun.R", local = TRUE)  

  runjs("openFullscreen(document.documentElement)")

})
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • It did not work. By the way, I am using `shinydashboard`. So maybe I couldn't put the ui side at the right place. Any suggestion about that? (under dashboardBody? or?) – maydin Aug 04 '21 at 14:02
  • @maydin Yes, in `dashboardBody`. Also try to put the `runjs` before the `source`. – Stéphane Laurent Aug 04 '21 at 14:10