-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
executable file
·72 lines (59 loc) · 2.05 KB
/
server.R
File metadata and controls
executable file
·72 lines (59 loc) · 2.05 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
library(shiny)
shinyServer(function(input, output) {
#Variable 'point' stores the location
#and class of each point
point <- reactiveValues(
x_cord = c(),
y_cord = c(),
class = NULL,
#Variables with prefix new_
#are used as auxiliary ones
#for creating the plot only
new_x = NULL,
new_y = NULL,
new_class = NULL,
#This table will store the dataset
table = NULL
)
#Observe the click event in the plot
observeEvent(input$plot_click, {
#Append the new data
point$x_cord <- c(point$x_cord, input$plot_click$x )
point$y_cord <- c(point$y_cord, input$plot_click$y )
point$class <- c(point$class, switch(input$button_class,
Positive = 'blue',
Negative = 'red') )
#For creating the plot
point$new_x <- input$plot_click$x
point$new_y <- input$plot_click$y
point$new_class <- switch(input$button_class,
Positive = 'blue',
Negative = 'red')
})
#Draw the points
output$plot <- renderPlot({
plot(0,0, cex = 0,
main = "Draw the points",
xaxt='n', xlab = '',
yaxt ='n', ylab ='')
points(point$x_cord, point$y_cord, pch = 21, cex = 1.2, bg = point$class)
points(point$new_x, point$new_y, pch = 21, cex = 1.2, bg = point$new_class)
})
#To download the data
output$downloadData <- downloadHandler(
filename = "cluster.csv",
content = function(filename){
#Create a vector with the classes
df_classes <- rep(0, length(point$class))
df_classes[point$class == 'blue'] <- 1
df_classes[point$class == 'red'] <- -1
#create the table
df_classes <- rep(0, length(point$class))
df_classes[point$class == 'blue'] <- 1
df_classes[point$class == 'red'] <- -1
point$table <- data.frame(x = point$x_cord, y = point$y_cord, class = df_classes)
#saves the file
write.csv(point$table, file = filename, row.names = FALSE)
}
)
})