-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableFile3col.R
115 lines (75 loc) · 2.56 KB
/
tableFile3col.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
tableFile3col <- function(input, output, session,
label_1 = "time", label_2 = "logS", label_3 = "temperature",
default_data = data.frame(x = 1, y = 1, z = 1)
) {
## File part
userFile <- reactive({
validate(need(input$file, label = "Text"))
input$file
})
file_frame <- reactive({
read.table(userFile()$datapath,
header = TRUE,
sep = input$sep,
dec = input$dec,
stringsAsFactors = FALSE)
})
excelFile <- reactive({
validate(need(input$excel_file, label = "Excel"))
input$excel_file
})
excel_frame <- reactive({
read_excel(excelFile()$datapath,
sheet = input$excel_sheet,
skip = input$excel_skip,
col_types = "numeric")
})
## Matrix part
input_manual <- reactive({
out <- input$manual_table
colnames(out) <- c(label_1, label_2, label_3)
as.data.frame(out)
})
## Select the right frame
out_table <- eventReactive(input$update_table, {
if (input$my_tabBox == "Old") {
input_manual()
} else if (input$my_tabBox == "Text") {
file_frame()
} else if (input$my_tabBox == "Excel"){
excel_frame()
} else {
hot_to_r(input$hot)
}
}, ignoreInit = FALSE, ignoreNULL = FALSE)
## Show the table
# output$my_table <- renderTable(out_table())
output$my_table <- renderPlot({
out_table() %>%
mutate(temperature = factor(temperature)) %>%
ggplot() +
geom_point(aes(x = time, y = logS, colour = temperature))
})
## Export the table
output$export_table <- downloadHandler(
filename = "mytable.csv",
content = function(file) {
write.table(out_table(),
file = file, row.names = FALSE, sep = "\t")
}
)
## Handsontable
output$hot = renderRHandsontable({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
DF = default_data
}
DF %>%
set_names(c(label_1, label_2, label_3)) %>%
rhandsontable() %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE)
})
# Return the reactive that yields the data frame
return(out_table)
}