Is it possible to set Shiny options to open an App automatically in a full view mode, i.e. in a maximized window?
My user interface is designed in a way that is nicely looking only when browsed in a full view.
My source is written in two standard files: server.R and ui.R.
I am interested in both options: to run app in (1) RStudio Window and in (2) External browser.
Although this appears to me as a natural and simple question, I cannot find any suggestion when searching the web. Does anyone know of a solution?
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:
You have a few options depending on the constraints of your circumstances, in no particular order:
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.
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.
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.
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.
An alternative to running full-screen is to open your app in a different browser from RStudio.
Next to the shiny app launch button there is a tiny triangle that opens a drop-down menu. Within this menu, just click on the icon to change the displaying option to Run External. If you change to external, every time you click Run App it will open in your default browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With