-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
50 lines (42 loc) · 1.33 KB
/
app.R
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(shiny)
library(readr)
library(ggplot2)
df <- read_csv("data/car_miles_per_person_per_week_london.csv")
df$label <- factor(df$label, levels = df$label)
df$col <- factor(df$label, levels = df$label)
ui <- fluidPage(
fluidRow(
column(width = 12,
plotOutput("plot1",
# Equivalent to: click = clickOpts(id = "plot_click")
click = "plot1_click",
brush = brushOpts(
id = "plot1_brush",
direction = "x"
)
)
)
),
fluidRow(width = 6,
h4("Brushed points"),
plotOutput("brush_info")
)
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(df, aes(x = label, y = val, fill = col)) + geom_bar(stat="identity")
})
output$click_info <- renderPrint({
# Because it's a ggplot2, we don't need to supply xvar or yvar; if this
# were a base graphics plot, we'd need those.
nearPoints(df, input$plot1_click, addDist = TRUE)
})
output$brush_info <- renderPlot({
if (!is.null(input$plot1_brush) && !is.na(input$plot1_brush)){
dat <- brushedPoints(df, input$plot1_brush)
# browser()
ggplot(dat, aes(x = label, y = val, fill = col)) + geom_bar(stat="identity")
}
})
}
shinyApp(ui, server)