Skip to content

Commit

Permalink
Add a test app for rstudio/shiny#2668 (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: Barret Schloerke <barret@rstudio.com>
  • Loading branch information
cpsievert and schloerke authored Jul 27, 2021
1 parent 1a4956e commit 0dedc77
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions apps/161-discrete-limits/app.R
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)

0 comments on commit 0dedc77

Please sign in to comment.