-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.R
47 lines (42 loc) · 1.41 KB
/
server.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
library(shiny)
library(ggplot2)
shinyServer(function(input, output, session) {
dataset <- reactive({
if(is.null(input$df)){
NULL
} else {
read.csv(input$df$datapath, header = T)
}
})
observe({
if(!is.null(input$df)) {
updateSelectInput(session, "x.variable",
label = "Horizontal Axis",
choices = names(dataset()),
selected = sample(names(dataset()), 1))
updateSelectInput(session, "y.variable",
label = "Vertical Axis",
choices = names(dataset()),
selected = sample(names(dataset()), 1))
updateSelectInput(session, "color.variable",
label = "Color",
choices = names(dataset()),
selected = sample(names(dataset()), 1))
}
})
output$plot <- renderPlot({
if(is.null(input$df)){
NULL
} else {
if(input$x.variable %in% names(dataset()) && input$y.variable %in% names(dataset())) {
if(input$should.color) {
ggplot() + geom_point(aes(dataset()[, input$x.variable], dataset()[, input$y.variable], color = factor(dataset()[, input$color.variable])))
} else {
ggplot() + geom_point(aes(dataset()[, input$x.variable], dataset()[, input$y.variable]))
}
} else {
NULL
}
}
})
})