COVAIL / photon

RStudio Add-in to build Shiny apps utilizing the Electron framework
125 stars 25 forks source link

App runs with blank screen. #21

Open py9mrg opened 4 years ago

py9mrg commented 4 years ago

I have used Photon to build the quick start app, but when I run the resulting .exe, the window opens with the circling orange thing, then flashes for a microsecond, then goes blank.

I thought maybe it was an issue with the quick-start app, so I tried the same by making an app.R out of the first example: https://shiny.rstudio.com/articles/basics.html

Same thing.

If I go within the resources folder of the resulting app to the R project and app etc that gets built, and manually run the app from there, it works fine. So, then I looked at the developer tools from the open (blank) instance of the .exe and see a completely blank frame:

image

Seems like the .exe isn't loading what it should.

Any ideas? Oh, Windows 10, btw. I do get some warnings during building about certain libraries being built under R 4.0.0 (e.g. purrr, sringr, magrittr, batch), which is weird as I don't know why it's saying that - I assume it's using those from my personal library, but the app I'm building isn't using them, I'm on 4.0.1, I'm not autoloading them with an .RProfile file, and they're not in the R-Portable library provided. I have no idea why it's loading them!

muzammilaz commented 4 years ago

In main.js there's a function being called on mainWindow.webContents.once. From what I understand, there's a line that reloads the app when the dom builds for the first time. mainWindow.reload() but there's a check around it which only reloads it if it's being run on MAC. I think it was there as some sort of workaround for MAC where they may have faced a similar problem. Anyways, removing the if statement and reloading it without any check fixes this for me.

py9mrg commented 4 years ago

Ah ok, I’ll give that a go later. Thanks a lot.

muzammilaz commented 4 years ago

If this doesn't do it. You can try logging uncaught exceptions and run it from the command line. process.on('uncaughtException', function (err) { console.log(err); })

orijitghosh commented 3 years ago

I also faced the same problem, never could solve it.

py9mrg commented 3 years ago

I did, by using a different package! Try electricShine instead. Just bear in mind that the latest version of golem has changed a few things (eg app initiation) so pay attention to how the demoApp in electricShine does things and copy those. It'll become clear when you try it, I hope.

bmfazio commented 3 years ago

I spent the last 48 hours trying to deal with electricShine to no avail as it kept erroring during the app building process

However! I did find a solution for the blank screen. At least in my case, it seems that for some reason the required libraries were not being installed into the portable R, causing it to crash when library was called, so I manually ran install.packages from the portable R executable.

The way I found out this was the issue was by running the Electron executable from cmd.exe, this allowed me to take a look at the R messages and figure out which libraries were missing. In my case, I had to install later, rlang and promises in addition to the ones I was actually using in my code, so it seems like there's some bug regarding the proper installation of dependencies during the app building step.

py9mrg commented 3 years ago

Strange, I had zero problems with it except having to make sure I used the run_app function as per the electricShine intro page / in the demo app the package installs (not the golem template one it mentions later in the help page). That fixed the blank screen for me. Never had any dependency issues, and I'm not sure it should given the way it's designed to use a shiny app that's an T package for that reason (it uses your package code to work out the dependencies). I suspect this is more something your end due to the way R packages work - did you make sure to run devtools::check()? Does your shiny app function correctly when you run it as an R package from R?

bmfazio commented 3 years ago

I was referring to the blank screen when using Photon, that was fixed by the manual install trick.

Regarding electricShine, I just cloned their demo app but kept getting an error message that went something like "merge is not a function" from node, had no idea what to do with that.

py9mrg commented 3 years ago

Oh I see. Yeah Photon's a no go now, I couldn't get it working either. I wouldn't waste your time to be honest. I'll try the demo app in eS again later. Sounds like a JavaScript issue - all these electron based apps depend on JS, npm etc and could be a dependency issue with that. You could do worse than post an issue on the eS page - the guy was pretty responsive when I did.

orijitghosh commented 3 years ago

Photon didn't work at all. They made it seem so easy.

petegordon commented 3 years ago

Definitely not easy. It was a goal, but definitely never achieved. The complexity of running Electron (NodeJS, Chromium) with an internal R-Portable instance running Shiny is a lot.

I'd suggest going to the source of how to create an Electron App with R-Portable inside of it.... (and not only run the electron exe from the command, but run R-Portable R from the command line and then run your shiny app from the command line within the R-Portable environment, to look for issues with the R/Shiny environment you have created and are running) https://github.com/ColumbusCollaboratory/electron-quick-start

The issue of a blank screen can be caused by two reasons... 1) the shiny app doesn't launch before electron view is made and 2) the shiny app and R-Portable environment throws an error.

Best of luck! Pull requests welcome... but this is complicated and may need to shut down the R Add-In. In favor of the electorn-quick-start above that is more foundational.

woodspock commented 3 years ago

For what it's worth, I get the white screen problem when I launch a newly created app or a modified one (using electron quick start and npm run package-win. Then I close the window, relaunch electron-quick-start.exe, and then it works !!???

bmfazio commented 3 years ago

That fits the first case described by @petegordon. Instead of closing the window, using the Reload option from the View menu should also work. The reason it also works the second time around is that the R executable doesn't close when the window does, which honestly seems like unintended behavior, but works out in the end. If you manually kill the process, the blank screen should come back once again.

AMillanFL commented 3 years ago

Hi, I have a blank screen also. The problem is that the app lauch perfectly on my computer (windows 10 with R 4.0.0. installed...) but when I run it from an other computer (also windows 10 but no R) I get blank screen (even if I restart or force reload). I get same sanction with electron-quick-start application. How can I see if computer config alter working ?

Many thanks !

bmfazio commented 3 years ago

That seems consistent with the portable version of R crashing due to lack of required libraries. Please read my comment here and give that a try. You'll have to find the R executable (should be in resources\app\R-Portable-Win\bin).

Wladimir-Sanyer commented 3 years ago

Greetings I have the same problem, I tried what you indicate and I do not think it is the problem since the screen does not appear blank on my computer, the problem is generated when I transfer the program to another computer (Windows 10), and a screen throws me in white. Besides that a zip file is not being generated, what I do is compress the entire electron folder and open it on another computer, there is a solution. It should be noted that I am doing everything with the Demo application

tomicapretto commented 3 years ago

I have also faced the problem you call "blank screen". Actually I have a loading scree, so I don't see a blank scree, but a spinner that never disappears.

I've been on this for weeks without being able to solve it, but at least I think I know where the problem is.

As far as I know, the problem with the blank screen (i.e. shiny app not finishing loading) is because mainWindow.loadURL('127.0.0.1' + port) never resolves and then the content is never loaded. Why this happens? I don't know. But at least I think I know this is not related to Photon/electricShine/etc. but a problem related to Electron itself.

I've tried with webPreferences: {webSecurity: false} when defining the browser window because by default Shiny uses http instead of https and it didn't work either. Sometimes I experience the same than @woodspock, the fist time I try to launch the app, it doesn't load. After closing and running again, it loads.

The problem that the app does not finish loading happens more often in computer with lower resources.

One alternative that comes to my mind, is to have

const { shell } = require('electron')

and then run shell.openExternal('127.0.0.1' + port) after executing the R function that launches the app and it will open the app in the default web browser. This is not as nice as having an app that loads in the chromium browser provided by Electron, but at least it allows the user to have access to the app.

I will keep trying. If I find a solution, I will post it here.

joe-chelladurai commented 3 years ago

This seems to work for me. I consider the "Listening on http://127- - - - - " as a message saying the app is now ready to be loaded on to the browser/Electron window. So I moved the mainWindow events inside a conditional.

 childProcess.stderr.on("data", (data) => {
    //  console.log(`stderr:${data}`);
    var string_output = `${data}`;
    console.log(string_output);

    if (string_output.includes("Listening") === true) {
      console.log("Ready");
      mainWindow.loadURL("http://127.0.0.1:" + port);
      mainWindow.maximize();
      mainWindow.show();
    } else {
      console.log("Not yet ready");
    }
  });

Notice the messages in the console where you run npm start.