Hopefully this'll be close to your goal.
The first hurdle is passing the text from R to Python. For this, the reticulate package is great. The second hurdle was the one you seem to care about, which is having a reactive chunk.
I approached it in a round-about way: instead of a reactive chunk, have knitr convert a character vector "chunk" to HTML within a reactive context. Then feed that HTML to renderUI.
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(shiny)
library(flexdashboard)
library(knitr)
library(reticulate)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r, e}
textAreaInput("text", label = h3("Paste Abstract Here"), width = '600px', height = '300px')
actionButton("submit", "Submit")
v <- reactiveValues()
renderUI(v[["py_chunk"]])
observeEvent(
input$submit,
{
var <- input$text
# Each chunk line is an element of the vector
py_code <- c(
"```{python}",
"test = str(r.var)",
"print(test)",
"```"
)
# Make sure knitr's converting to HTML
knitr::render_html()
# Then store the output in the reactive value
v[["py_chunk"]] <- HTML(knitr::knit(text = py_code))
}
)
```
Hopefully it works for you. R is calling Python, so the OS environment comes into play. I had trouble with bit-mismatches between R and Python at first, but then it stopped, which worries me all the more.