posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
144 stars 13 forks source link

How to run the app after creation using R shinylive? #58

Open dmresearch15 opened 4 months ago

dmresearch15 commented 4 months ago

I've successfully created an app using r shinylive in a local drive \app1.

Now I can run this app using httpuv::runStaticServer("\app1") in RStudio on Windows 10.

Now how can I run this app in my browser without R and R server?

Now what should I do so others can view it without R and R server.

seanbirchall commented 4 months ago

You need to 'host' or 'start' the app using a static web server. When you run httpuv::runStaticServer("\app1") httpuv starts a static web server that will run the static assets for your shinylive app.

You can do something similar in VS Code by using the addin live server which essentially does the same as httpuv::runStaticServer("\app1")

If you want the app to run in the browser without being started from your local desktop you need to host it on something like github pages, AWS S3, or any other static web server hosting solutions. I recommend github pages as it's free, just create a repo with your exported shinylive app, and use github pages to host it.

If your shinylive app is something internal for say a company then you will want to host it on an internal solution, like your companies github (create a repo on your companies github and use pages there) or an S3 like service which is protected by your companies firewall/vpc. You should talk with the right people in IT first.

dmresearch15 commented 4 months ago

I aim to have the application operate within a browser environment, independent of my local desktop. Given the sensitive nature of the data involved, I intend to consult our company's IT department for guidance.

Additionally, I've attached a PNG file displaying the contents of the \app1 directory. Is it necessary to transfer all files from the \app1 directory to the designated location?

Capture

What’s the command one needs to issue to run the app in the browser environment?

seanbirchall commented 4 months ago

You will need all the files.

All of the files will also be available to any user that has access to the app. So if this data is sensitive to a point that users viewing the app shouldn't have direct access to the data files then you will likely need a more complex solution or a different solution entirely.

You should probably mention to your IT department that you would like to host a client side web app and need a static web server to host it. This web app is compiled to WASM and any data compiled with this app will be accessible by any user who has permission to interact with the app.

There isn't any specific command to do this, the files/folders just need to be placed in a location where a static web server can point to them and host them, like the options I mentioned above. The static web server will then have a URL (the location of the shinylive directory) which you can visit to interact with the web app.

dmresearch15 commented 4 months ago

I appreciate your prompt reply. Your insights will be invaluable to me.

kwakuduahc1 commented 1 month ago
  1. You can put it on the network drive. Since it is an HTML file, others with access to the drive can open it with their browsers (by default on most PCs). It may complain about security.
  2. You can set up IIS windows (A few clicks in the control panel) to host static files (or more advanced executables). You may have to open a port through the firewall service as well.
  3. Download third-party web servers, e.g. Apache, Caddy, etc. to serve the file. I have not used caddy before but it should be simple to configure.

In 2 and 3, you may have to open a firewall port.

At the risk of providing unnecessary information, let me know if you need help setting up IIS.

serrulate commented 2 weeks ago

i am trying to host a shinylive application on windows webserver, I moved the files to the webserver, however when i try and navigate to the index file, i'm getting the following error in the console any thoughts on this error?

Uncaught (in promise) RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info.

georgestagg commented 2 weeks ago

Uncaught (in promise) RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info.

The values 3c 21 44 4f in hex are the string <!DO in ASCII. This is likely the start of <!DOCTYPE html>, meaning the web server is sending a HTML page rather than the a .wasm WebAssembly file. Possibly this is a "file not found error", but it is hard to say from the message above alone.

I would check to make sure all the required files from the output from shinylive have been uploaded correctly, including content in subdirectories. Also check to make sure that the webserver is not trying to redirect certain URLs. To debug further, the web browser's Developer Tools can tell you more about what network errors are raised for each individual content URL under the "Network" tab.

serrulate commented 2 weeks ago

My suspicion is it is a setting in the webserver, but i'm having trouble figuring out what. in the webserver i added a MIME Type of .wasm applicatoin/wasm which removed the previous error i was receiving, but now receiving the following. console and network errors console1 network1

georgestagg commented 1 week ago

If adding a MIME type was required for the .wasm files to not return a 404 error, it will likely also be required for the following binary file types:

.so - application/octet-stream .data - application/octet-stream