Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing large apps when the shinylive.io sharing link is over 32,000 characters #80

Open
JoaoGarcezAurelio opened this issue May 20, 2024 · 9 comments

Comments

@JoaoGarcezAurelio
Copy link

Hi there,

I hope you are well. I am contacting because having followed the youtube videos about shinylive I found it to be very interesting. Having managed to create a shiny app in shinylive.io, I was surprised that when it came to sharing the link said link had over 32000 characters, meaning it could not be used in shortening url websites. I am wondering if this is something the team plans to address in the future?

Thank you!

@seanbirchall
Copy link

@JoaoGarcezAurelio For apps that have too large of a code base there's not much that can be done aside from creating some lookup table service. Possible example: Posit has allowed for free publishing of rmd documents on rpubs since I started writing R code. They could create a service that publishes a share linked code as some uuid or md5 function of the underlying code. Which then fetches the actual code saved to this additional service using said uuid or md5 as the lookup.

Right now shinylive py/r just uses a compression algorithm + base64 url encoded strings which allows shinylive users to share links without this additional service so long as they're not too large. Most browsers have a limit around ~2000 characters so if this string is longer than that for large apps there's not much that can be done aside from creating an additional service which costs money.

@georgestagg
Copy link
Collaborator

Hi @JoaoGarcezAurelio, if your sharing URL is too long here are two alternative approaches you could try:

  1. Rather than building your Shiny app in shinylive.io, instead create a local traditional Shiny app on your machine and use the {shinylive} package's export() function to create a bundle of static files. Instructions are here. `the output folder can then be shared via GitHub Pages, Netlify Drop, or any other static file hosting service.

  2. Alternatively, you could create a GitHub gist containing your Shiny app code. The Shinylive website for both R and Python supports loading an app via Github gist. See the documentation here for more information and instructions. Though, for R apps be sure to change the /py/ parts of the URL in the instructions to /r/, so that the Shiny for R engine is loaded.

@JoaoGarcezAurelio
Copy link
Author

Hi @seanbirchall and @georgestagg, thank you both for taking time to reply to this query, I really appreciate it. With regard to the shinylive option that @georgestagg mentioned, that was my initial aim, but I am unable to get it to render as I get a warning stating that "Robj construction for this JS object is not yet supported". I also tried shinyio but there I get a different error, flagging libarchive, which I have been told in stackoverflow is due to shiny not supporting libarchive at the moment. I will try the GitHub gist option suggested. I will try to also look into @seanbirchall suggestion, I was not able to follow some of the input but will try to research it.
Finally, thank you both for working on this. It may be you hear this often, but these types of options are brilliant and make a real difference to non-technical people like me.

@georgestagg
Copy link
Collaborator

georgestagg commented May 21, 2024

I am unable to get it to render as I get a warning stating that "Robj construction for this JS object is not yet supported"

That is a fairly generic error that just indicates something has gone wrong internally between Shinylive and webR. Are there any other error messages in the JavaScript console? It would be good to track down exactly what is causing it, so if you can share a small reproducible app that causes that error that would be very useful.

In the meantime, ensuring sure you're running the latest version of the r-shinylive package:

install.packages("shinylive")

and that the shinylive assets are up to date:

shinylive::assets_download()

might help.

@JoaoGarcezAurelio
Copy link
Author

Hi @georgestagg, happy to share it, I based the app on Garret Gromelund's feedback on shiny apps and followed your Youtube talk mentioning how to best implement the process. The app is here: https://github.com/JoaoGarcezAurelio/Passport-survey-completion/tree/main/completion_rates_app and it runs in my machine and in the shinylive.io. Would you advise sharing it in a particular setting? Will implement your suggestion, I assume shinylive is up to date as i updated it a couple of days ago, but will run the assets. Thank you once again for all the suggestions and time!

@gadenbuie gadenbuie changed the title Shinylive.io sharing link Sharing large apps when the shinylive.io sharing link is over 32,000 characters Jun 26, 2024
@georgestagg
Copy link
Collaborator

Sorry it's taken me a while to get back to this.

@JoaoGarcezAurelio, were you able to share your app in the end? I unfortunately cannot access the URL you posted above for testing.

An alternative method I've just thought of would be to embed your app in a Quarto document using the Quarto Shinylive extension: https://github.com/quarto-ext/shinylive, and then publishing the resulting document on e.g. GitHub Pages.

@JoaoGarcezAurelio
Copy link
Author

JoaoGarcezAurelio commented Aug 27, 2024

Hi @georgestagg , no problem whatsoever, thank you for getting back to me. I ended up deleting the repository.
That sounds like an interesting option, I assume that would allow users to manipulate the shiny app within quarto on GitHub Pages without needing to have access to R, as it would serve a shiny app on a static website but embedded in the Quarto document? Will follow the link you provided and look more into it, from a quick perusal it seems like it requires some Python knowledge which I will need to acquire. Thank you for all your work on getting these processes to be feasible, it makes a big difference!

@georgestagg
Copy link
Collaborator

That sounds like an interesting option, I assume that would allow users to manipulate the shiny app within quarto on GitHub Pages without needing to have access to R, as it would serve a shiny app on a static website but embedded in the Quarto document?

Yes, that's correct.

Will follow the link you provided and look more into it, from a quick perusal it seems like it requires some Python knowledge which I will need to acquire.

You shouldn't need any direct Python knowledge, it's just that the README for that repository was written before Shinylive for R was available, so it's directly targeting Shinylive for Python.

In principle, the following should be enough to get a shinylive for R app up and running in Quarto:

Step 1: Install the shinylive extension, running the following in a terminal with the current directory set to a Quarto project:

quarto add quarto-ext/shinylive

Step 2: Create a document including a shinylive for R app:

---
title: Shinylive in Quarto
format: html
filters:
  - shinylive
---

:::{.column-screen}

```{shinylive-r}
#| viewerHeight: 600
#| components: [editor, viewer]
#| standalone: true
library(shiny)
library(bslib)

ui <- page_sidebar(
  title = "Hello Shiny!",
  sidebar = sidebar(
    sliderInput(
      inputId = "bins",
      label = "Number of bins:",
      min = 1,
      max = 50,
      value = 30
    )
  ),
  plotOutput(outputId = "distPlot")
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    x <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    hist(
      x,
      breaks = bins,
      col = "#75AADB",
      border = "white",
      xlab = "Waiting time to next eruption (in mins)",
      main = "Histogram of waiting times"
    )
  })
}

shinyApp(ui = ui, server = server)
```

:::

Once you are happy, you'd publish the Quarto document in the usual way, by running:

quarto publish

in a terminal.

@JoaoGarcezAurelio
Copy link
Author

Brilliant, will give that a try :)

Thank you for taking the time to help, it makes a massive difference 👍🏼

All the best and have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants