shinylive-r: cannot include R file

To include files in a Shinylive app in a Quarto document, the files need to be included in the shinylive-r chunk using the ## file: {filename} comment header. In your case, this would look something like this:

```{shinylive-r}
#| standalone: true
#| viewerHeight: 300

source("R/test-shiny.R", local = TRUE)


library(shiny)

ui <- fluidPage(
    textInput("name",  msg1),
    textOutput("greeting"),
)

server <- function(input, output, session) {
    output$greeting <- renderText({
        paste0(msg2, input$name)
    })
}

shinyApp(ui, server)

## file: R/test-shiny.R
msg1 <-  "What's your name? "
msg2 <-  "Hello "
```

You can think of each shinylive cell as a complete, self-contained app, and all of the apps files need to live in the cell.

When you have multiple files, I find it helpful to take advantage of Quarto's {{< include >}} shortcode. For multi-file apps, I usually store the app source code, including the app.R file, in a subdirectory next to the post. This way, I can run the app directly outside of Quarto in the usual way during development, while also being able to bundle the app into the Quarto document with shinylive:

```{shinylive-r}
#| standalone: true
#| viewerHeight: 300

## file: app.R
{{< include demo-app/app.R >}}

## file: R/test-shiny.R
{{< include demo-app/R/test-shiny.R >}}
```
2 Likes