From 81697f3110baeaade6bf26038736f565d0a9cda7 Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 16 Oct 2019 17:34:42 -0500 Subject: [PATCH] modify 161 to account for missing values, provides a test for https://github.com/rstudio/shiny/pull/2668 --- 161-discrete-limits/app.R | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/161-discrete-limits/app.R b/161-discrete-limits/app.R index 8d765010..651a9d73 100644 --- a/161-discrete-limits/app.R +++ b/161-discrete-limits/app.R @@ -17,7 +17,9 @@ ui <- basicPage( uiOutput("res1"), br(), plotOutput("plot2", brush = "brush2"), - uiOutput("res2") + uiOutput("res2"), + plotOutput("plot3", brush = "brush3"), + uiOutput("res3") ) server <- function(input, output) { @@ -91,6 +93,48 @@ server <- function(input, output) { } }) + dat <- data.frame( + x = c("a", "b", NA, NA), + y = c(1, 2, 3, 2), + key = c("a", "b", "c", "d"), + stringsAsFactors = FALSE + ) + + output$plot3 <- renderPlot({ + ggplot(dat) + + geom_point(aes(x, y)) + + facet_wrap(~x, scales = "free") + + geom_rect( + data = data.frame( + x1 = 0.8, + x2 = 1.2, + y1 = 2.9, + y2 = 3.1, + x = NA + ), + aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2), + alpha = 0, color = "black", lty = 2 + ) + + ylim(1, 4) + }) + + brush3key <- reactive({ + if (is.null(input$brush3)) return(NULL) + brushedPoints(dat, input$brush3)$key + }) + + output$res3 <- renderPrint({ + if (is.null(brush3key())) { + return(tags$b("Brush the points outlined above")) + } + actual <- brush3key() + if (identical(actual, "c")) { + tags$b("Test passed!", style = "color: green") + } else { + tags$b("Test failed", style = "color: red") + } + }) + } shinyApp(ui, server)