Description Usage Arguments Value Examples
Safely render a ggplot
in Shiny application
1 | safe_ggplot(expr, data = NULL, session = shiny::getDefaultReactiveDomain())
|
expr |
Code to produce a |
data |
Argument passed to |
session |
Session object to send notification to. |
Output of ggplot_build
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | if (interactive()) {
library(shiny)
library(ggplot2)
ui <- fluidPage(
fluidRow(
column(
width = 3,
selectInput(
inputId = "var",
label = "Var:",
choices = c("Sepal.Width", "Do.Not.Exist")
)
),
column(
width = 9,
plotOutput(outputId = "plot")
)
)
)
server <- function(input, output, session) {
output$plot <- renderPlot({
p <- ggplot(iris) +
geom_point(aes_string("Sepal.Length", input$var))
safe_ggplot(p)
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.