r-wasm / quarto-drop

Drop down an interactive R or Python console, code editor, and plotting window from the top of your Quarto slides.
https://r-wasm.github.io/quarto-drop/
MIT License
157 stars 4 forks source link

Possible to run a simple Shiny app? #7

Closed joshcullen closed 3 months ago

joshcullen commented 3 months ago

This seems like a really great extension, especially for teaching purposes!

Not sure if it's possible to run a Shiny app with the way things are set up, but I received a Error in utils::browseURL(appUrl) : 'browser' must be a non-empty character string and wasn't able to resolve the error by specifying shinyApp(ui, server, options = list(launch.browser = TRUE)). Do you know if there's an argument that can be specified to resolve this? Below is the example code I used for the app:

library(shiny)

ui <- fluidPage(
  titlePanel("Old Faithful"),
  sidebarLayout(
    sidebarPanel = sidebarPanel(
      sliderInput(inputId = "bins", label = "Number of bins:",
            min = 1, max = 50, value = 30)
    ),
    mainPanel = mainPanel(
      plotOutput("distPlot")
    )
  )
)

server <- function(input, output, session) {

     output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      wait <- faithful[, 2] 
      bins <- seq(min(wait), max(wait), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(wait, breaks = bins, col = 'darkgray', border = 'white')
   })

}
coatless commented 3 months ago

@joshcullen approach to be taken would likely be to use the {quarto-shinylive} extension and create a code cell that has the editor and viewer components, e.g.

```{shinylive-r}
#| standalone: true
#| components: [editor, viewer]

# app code from your example

Alternatively, you can embed the [shinylive editor](https://shinylive.io/r/editor) website directly into a presentation, c.f. 

````md
## shinylive REPL

```{=html}
<iframe allow="cross-origin-isolated" style="display:block; margin: 0 auto;" width="90%" height="75%" src="https://shinylive.io/r/editor">
</iframe>


Swap the `src` part of the `iframe` with the shinylive app share URL if needed.
georgestagg commented 3 months ago

Yes, I definitely think the right way to do this is using shinylive, as @coatless describes above.

The intention for this extension is really just to provide a simple scratch pad for impromptu scripting, rather than supporting complex applications such as Shiny apps. For that reason I'm going to close this issue in favor of pointing towards the quarto-shinylive extension.

EDIT: The quarto-shinylive GitHub readme doesn't make it clear, but it also works with R Shiny apps. Updating the docs to reflect this is on our radar.