I've written an app which renders an r-markdown -report as html inside bsmodal, when user presses button.
It works, but it only works once. If the modal is closed and the button is entered again, the rmarkdown is not rendered anymore. If I place a renderText inside the modal instead of renderUI-part, it works OK. Does someone know why the rmarkdown gets rendered only the first time the button is pressed?
Thanks for any help,
-Kari
Minimized example code provided below.
Shiny code:
setwd("") #Set working directory here
ui <- function(id) {
fluidPage(
fluidRow(
column(3,
actionButton("button", "Go!")
)
)
)
}
server <- function(input, output) {
observeEvent(input$button, {
showModal(modalDialog(
title = "Fancy report",
tagList(
renderUI(
HTML(
readLines(
rmarkdown::render("report.rmd",
encoding = "UTF-8",
envir = new.env()
), encoding = "UTF-8"
)
)
)
),
easyClose = TRUE
)
)
})
}
shinyApp(ui = ui, server = server)
rmarkdown (please notice, stack interprets those 3 markdown ticks as code block start and end as well):
---
mainfont: Arial
output: html_document
---
```{r echo = FALSE, comment=NA, results='asis', warning=FALSE, message=FALSE}
library(knitr)
library(kableExtra)
library(tidyverse)
library(dplyr)
ds <- head(mtcars)
ds %>% kable("html", escape = F, col.names = NULL, table.attr = "style='width:90%;'")
question from:
https://stackoverflow.com/questions/66047472/r-shiny-showmodal-and-rmarkdown-report 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…