. reactiveValue . , . , , , . diamond ggplot2, , .
shinyApp(
shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("x", "X", choices=names(diamonds)),
selectInput("y", "Y", choices=names(diamonds)),
checkboxInput("line", "Add line")
),
mainPanel(
plotOutput("plot")
)
)
)
),
shinyServer(function(input, output, session) {
data(diamonds)
vals <- reactiveValues(pdata=ggplot())
observe({
input$x; input$y; input$line
p <- ggplot(diamonds, aes_string(input$x, input$y)) + geom_point()
if (input$line)
p <- p + geom_line(aes(group=cut))
vals$pdata <- p
})
observeEvent(vals$pdata,{
output$plot <- renderPlot({
isolate(vals$pdata)
})
})
})
)