Shiny interactivity with grid graphics

homeblogmastodonblueskythingiverse



This post may be of interest to a very small number of people. Using a fancy grid-based graphics library in R such as lattice and want some Shiny brushing goodness? Sadly, Shiny only supports base graphics and ggplot2.

Solution: First work out the name of the relevant viewport (grid.ls(viewports=T,grobs=F)), then use the gridBase package to set up a corresponding base graphics viewport.

output$plot <- renderPlot({

    # ... draw some grid graphics ...

    seekViewport("...someviewport...")
    par(new=T, plt=gridBase::gridPLT())
    plot(1, type="n", axes=F, 
         xlab="", ylab="", 
         xlim=c(0,1), ylim=c(0,1),
         xaxs="i", yaxs="i")
})

If the viewport isn't named, tell the developer of the package to name their viewports.




[æ]