From 0dedc77e6e7e73f6cf2096d20196e5329b56a727 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Tue, 27 Jul 2021 14:08:54 -0500 Subject: [PATCH] Add a test app for https://github.com/rstudio/shiny/pull/2668 (#169) Co-authored-by: Barret Schloerke --- apps/161-discrete-limits/app.R | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/apps/161-discrete-limits/app.R b/apps/161-discrete-limits/app.R index 4c5540d29c..675b193880 100644 --- a/apps/161-discrete-limits/app.R +++ b/apps/161-discrete-limits/app.R @@ -1,6 +1,5 @@ ### Keep this line to manually test this shiny application. Do not edit this line; shinycoreci::::is_manual_app - library(shiny) library(ggplot2) library(dplyr) @@ -20,7 +19,9 @@ ui <- basicPage( uiOutput("res1"), br(), plotOutput("plot2", brush = "brush2"), - uiOutput("res2") + uiOutput("res2"), + plotOutput("plot3", brush = "brush3"), + uiOutput("res3") ) server <- function(input, output) { @@ -94,6 +95,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)