1

I develop a shiny app with a manager interface. This interface allows a statistician to import data and create plots. I would like to save the html element to display on the user page by renderUI({HTML(content)}). The same question is ask on rstudio community website : https://community.rstudio.com/t/how-can-i-save-r-shiny-html-output-to-an-external-file/89415

For example on the example below how to save the content of htmlOutput('content')

enter image description here

library(shiny)
library(datasets)
library(shinyjqui)

# Global variables 
n <- 200

# Define the UI
ui <- fluidPage(
  
  numericInput('n', 'Number of obs', n),
  selectInput("region", "Region:", 
              choices=colnames(WorldPhones)),
  br(),br(),
  
  htmlOutput('content')
)


# Define the server code
server <- function(input, output) {

output$content <- renderUI({
fluidRow(
      jqui_resizable(column(6, plotOutput('plot1'))),
      jqui_resizable(column(6, plotOutput('plot2')))
    )
})
  
output$plot1 <- renderPlot({
    hist(runif(input$n))
  })

output$plot2 <- renderPlot({
barplot(WorldPhones[,input$region]*1000, 
          main=input$region,
          ylab="Number of Telephones",
          xlab="Year")
})

}

shinyApp(ui = ui, server = server)

Thank you for your reply

  • If you want users to download a dynamically generated HTML file you have to user rmarkdown, knit to HTML and provide a download link in the app (which triggers the knitting of the rmarkdown). – JohnCoene Aug 19 '21 at 10:22
  • The goal is not to download in html by user. But to save the bookmarkings done in the admin page and display the content in the user page. – I found `jqui_bookmarking()` [](https://yang-tang.github.io/shinyjqui/articles/save-and-restore.html) which allows to do bookmarking state with the functions of **shinyjqui** package . – idea : save the state of the admin page and get a URL that will restore the application for the user. – But I notice that it does not take into account the htmlOutput('content') in the UI and `output$content <- renderUI({ fluidRow( ... )})` in the server. – Armel Soubeiga Aug 19 '21 at 12:04
  • Sorry, I'm confused. Don't you just need shiny's [built-int bookmarking feature](https://shiny.rstudio.com/articles/bookmarking-state.html)? – JohnCoene Aug 20 '21 at 08:50
  • Sorry I'll try to explain better. – Option 1: I want a solution to save id="content" (corresponding to my shiny::htmlOutput) as html. Then use includeHTML in the user page. – Option 2: use shiny's Bookmarking to save stage and load after in the user page. – option 1, I idn't find solution. And option 2 Bookmarking seems not to take into account the packge shinyjqui and doesn't take into account the `output$content <- renderUI({ fluidRow( ... )})` in the server. – Armel Soubeiga Aug 20 '21 at 12:09

0 Answers0