flexdashboard isolate file input for child Rmd

I'm trying to incorporate an Rmd I have been using into a flexdashboard. I'm curious if it is possible to use isolate() on an uploaded file and use it as-is rather than writing a bunch of reactive functions. If this is my template, is it possible to get a static object named df that the child document can go ahead and run with?

---
title: "help"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
---

```{r}
fileInput("data", "select data")

df <- isolate(input$data)
```

```{r, child="some_code.Rmd"}
```

My real example does something completely different but let's say some_code.Rmd looks like this:

---
title: "some code"
output: html_document
---

```{r packages, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
library(tidyverse)
```

The data looks like this:
```{r}
as_tibble(df)
```

The numeric data can be summarized with the following means
```{r}
df |> 
  summarise(across(where(is.numeric), mean)) |> 
  gather()
```

This ended up working:

knitr::knit() + markdown::markdownToHTML() + HTML() ---> renderUI()

    ---
    title: "help"
    runtime: shiny
    output: 
      flexdashboard::flex_dashboard:
        orientation: rows
    ---
    
    Sidebar {.sidebar}
    ==============================================
    ```{r file-input}
    fileInput("data", "select data")
    ```
    
    Row
    ==============================================
    
    ```{r knit-child}
    observeEvent(input$data, {
      df <- isolate(read.csv(input$data$datapath))
      new_env <- list2env(list(df = df))
      
      output$res <- renderUI({
        knitr::knit("some_code.Rmd", quiet = TRUE, envir = new_env) |> 
          markdown::markdownToHTML() |> 
          HTML()
      })
    })
    
    uiOutput("res")
    ```

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.