2
votes

I am able to launch the shiny app when chrome browser is already open in my desktop (linux). However, with my browser closed, and I launch the shiny app, it just shows a blank page and "waiting 127.0.0.1 ..." in lower status bar. In other words, it launches chrome but does not show the shiny app content. Here is my code:

library(shiny)
library(shinyBS)

launch.browser = function(appUrl, browser.path='/usr/bin/chromium-browser') {
  system(sprintf('"%s" --disable-gpu --app="data:text/html,<html>
<head>
<title>Configuration</title>
</head>
<body>
<script>window.resizeTo(800,500);window.location=\'%s\';</script>
</body></html>"', browser.path, appUrl))
}

shinyApp(

  ui = fluidPage(
    fluidRow(
      br(),
      wellPanel(
        fluidRow(
          h4('User Information')
        ),
        fluidRow(
          column(4,
            textInput('Name', 'Full Name', value = "")
          ),
          column(4,
            numericInput('accNum', 'Account Number', value = "")
          ),
          column(4,
            textInput('token', 'Account Token', value = "")
          )
        )
      )
    ),

    fluidRow(
      column(12,
         actionButton('save', 'Save')
      )
    ),
    bsTooltip(id = "accNum", title = "Enter Lending Club account number", 
              placement = "bottom", trigger = "hover")
    # tags$head(tags$style(type="text/css", "#accNum {width: 100px}"))
  ), 

  server = function(input, output, session) {
    session$onSessionEnded(function() {
      stopApp()
    })
    observe({
      if (input$save == 0)
        return()
      isolate({
        j<<-input$accNum
      })
    })

  },
  options = list(launch.browser=launch.browser)
)

Thanks for any help

* Edit 1 *

I have verified that the browser starts fine and goes to a specified URL outside of shiny:

system('/usr/bin/chromium-browser --disable-gpu --app="data:text/html,<html>
<head>
<title>Configuration</title>
</head>
<body>
<script>window.resizeTo(800,500);window.location=\'http://www.facebook.com\';</script>
</body></html>"')

The above also works inside shiny using the location facebook.com. However, when I change it to appUrl parameter it never connects. I also verified that the source of the page is pointing to the correct 127.0.0.1:3189, however, it looks like shiny is not responding for some reason...

2
What if, from code, you launch chrome then launch the app inside that window? I assume 127.0.0.1 is your local machine or the machine your shiny app is running on? - CalebB
Thanks for the suggestion, but I would prefer not having to do a work around. Shiny should be able to start the browser based on the documentation I have read. However, there is something is causing it to not start even though the same launch command works fine outside of Shiny - John Richardson

2 Answers

2
votes

Answered by shiny github folks:

"This is due to a problem with your shell script.

You need to add & to run the browser in the background. Otherwise, after R launches the browser, the browser won't return control back to R until after the browser process ends.

The reason it's not a problem when chromium is already open is because chromium responds differently to the command if the browser is already open -- it always returns immediately, even if the command doesn't have &."

Update

Here is the exact script I use:

launch.browser = function(appUrl, browser.path=path) {
  system(sprintf('"%s" --disable-gpu --app="data:text/html,<html>
    <head>
    <title>System Configuration</title>
    </head>
    <body>
    <script>window.resizeTo(830,675);window.location=\'%s\';</script>
    </body></html>" &', browser.path, appUrl))
}
1
votes

For me the answer suggested by John did not work. Not sure why... maybe some Chrome settings changed since December 2014.

What worked in my case was to use shell(..., wait=FLASE) instead of system(...).

launch.browser = function(appUrl, browser.path=path) {
  system(sprintf('"%s" --disable-gpu --app="data:text/html,<html>
  <head>
    <title>System Configuration</title>
  </head>
  <body>
    <script>window.resizeTo(830,675);window.location=\'%s\';</script>
  </body></html>" &', browser.path, appUrl), wait=FALSE)
}