Hello, I have a Shiny app that displays a table of information where each row of that table is defined using custom HTML. Within the HTML I have a place to display a plot. Currently I am pre-generating all potential plot images I would need and serving them up as .png in the code. I would like to replace these static images with interactive ggplot outputs, but can't figure out how to embed this functionality within the HTML block. Here is a super simplified version of what I'm trying to do.
ui.R
library(shiny)
library(shinydashboard)
library(ggplot2)
menuWidth=300
header <- dashboardHeader(titleWidth=menuWidth)
sidebar <- dashboardSidebar(width=menuWidth,
tags$head(tags$style(HTML('.content-wrapper {}'))),
sidebarMenu(style = "position: fixed; overflow: visible;",
uiOutput('cyl_dropbox')
)
)
body <- dashboardBody(
tabBox(width=10,
tabPanel('Plots',
fluidRow(
column(width=1),
column(width=10,
h2('Normal plotOutput object'),
plotOutput('car_plot1')
),
column(width=1)
),
fluidRow(
br(),
br(),
htmlOutput('car_plot2')
)
)
)
)
suppressWarnings(dashboardPage(header, sidebar, body))
server.R
html_template <- function()
{
tags$div(class="well",
style="margin-block-end:0.5em;",
tags$div(class="row",
tags$div(class="col-md-9",
tags$div(class="row",
tags$div(class="col-md-4",
tags$h5(style="margin-block-end:0em; margin-top: 0px; font-weight: bold;", "Stuff"),
tags$p(style="margin-block-end:0em;", "sub stuff"),
tags$p(style="margin-block-end:0em;", "other stuff"),
tags$p(style="margin-block-end:0em;", "more stuff")
),
tags$div(class="col-md-2",
tags$h5(style="margin-block-end:0em; margin-top: 0px; font-weight: bold;", "Things"),
tags$p(style="margin-block-end:0em;", "that thing"),
tags$p(style="margin-block-end:0em;", "those things"),
tags$p(style="margin-block-end:0em;", "the other thing")
)
)
)
),
tags$div(
tags$div(class="row",
tags$div(class="col-md-11",
hr(),
## This is how im currently doing it, using preprocessed static images
tags$img(src="http://drive.google.com/uc?export=view&id=0By6SOdXnt-LFaDhpMlg3b3FiTEU"),
tags$h5('How do I replace this static image with the interactive ggplot output above?')
)
)
)
)
}
attach(mtcars)
shinyServer(function(input, output, session)
{
## ------------------------------------
## DROP DOWN
## ------------------------------------
output$cyl_dropbox <- renderUI({
cyl_list <- sort(unique(mtcars$cyl))
selectInput('cyl_dropbox', 'Select Num Cylinders', cyl_list, selected=cyl_list[1])
})
## ------------------------------------
## PLOTS
## ------------------------------------
## normal plot
output$car_plot1 <- renderPlot({
temp <- subset(mtcars, cyl == input$cyl_dropbox)
p <- ggplot(data=temp, aes(x=hp, y=mpg)) + geom_point()
return(p)
})
## plot wrapped in custom HTML
output$car_plot2 <- renderUI({
html_list <- list()
html_list[[1]] <- html_template()
return(html_list)
})
})
Any help is appreciated, thanks!