How to run R Shiny App in full-sized window?

What you are asking for is browser dependent and cannot be enforced from R or Shiny. I had this same requirement for a conference where I deployed an app as a team activity, all the conference tables had a connected tablet. Note that the reason why this is difficult comes down to security and the risks of phishing / social engineering. Some additional information on this:

  • Fullscreen specification
  • Using the HTML5 Fullscreen API for Phishing Attacks - Feross.org

You have a few options depending on the constraints of your circumstances, in no particular order:

  1. Request for the browser to switch to fullscreen mode via javascript

    There is a Fullscreen API you could use to request the browser to switch to fullscreen mode. The benefit here is that it is browser and platform agnostic provided the browser supports the API. However, it is only a request and not guaranteed to work as intended. This question (and this one) demonstrates an implementation, you could use the excellent shinyjs package if you choose to go down this path.

    Here is a minimal example demonstrating the use of the Fullscreen API. using an adaptation of the Old Faithful Geyser Data demonstration app.

    app.R

    library(shiny)
    library(shinyjs)
    
    jsToggleFS <- 'shinyjs.toggleFullScreen = function() {
        var element = document.documentElement,
          enterFS = element.requestFullscreen || element.msRequestFullscreen || element.mozRequestFullScreen || element.webkitRequestFullscreen,
          exitFS = document.exitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen;
        if (!document.fullscreenElement && !document.msFullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
          enterFS.call(element);
        } else {
          exitFS.call(document);
        }
      }'
    
    ui <- fluidPage(
    
      useShinyjs(),
      extendShinyjs(text = jsToggleFS),
    
      titlePanel("Old Faithful Geyser Data"),
    
      sidebarLayout(sidebarPanel(
        sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
        div(
          HTML("<button type='button'>Toggle Fullscreen</button>"),
          onclick = "shinyjs.toggleFullScreen();"
        )
      ),
    
      mainPanel(plotOutput("distPlot")
    
      ))
    )
    
    server <- function(input, output) {
    
      output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
      })
    }
    
    shinyApp(ui = ui, server = server)
    

    N.B. If you are implementing this, you may choose something more advanced than my very simplistic HTML button. It is important to note that browsers will only allow the use of the API if initiated by the user. You may find the message Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture. in your javascript console if not detected as a user event.

    There is also the screenfull.js library, which tries to package up the API in a more friendly way.

  2. Deploy your app using some form of kiosk mode

    Browsers can be instructed to start in kiosk mode (i.e. fullscreen), see here for an example with Chrome on windows. The problem here of course is that unless you are working in a standard environment (like an enterprise) this could be highly frustrating to execute.

  3. Use a browser that is specifically designed to use fullscreen mode all the time

    Because my platform was android for the conference, I used an app (not this one but similar) and I placed a shortcut link on the main page after making this browser the default for opening pages. Not ideal, but it met my immediate requirements.

  4. Accept current state / Inform users

    Given there is a level of fragility with the available solutions and security concerns regardless of how you choose to tackle this problem, you may opt to accept the current state and layout your app as best you can with this knowledge. Or possibly just inform your users that the app is optimised for use fullscreen and that they can press F11 (or equivalent) in their browser to enable that.

Tags:

R

Shiny