-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_input.R
57 lines (43 loc) · 1.43 KB
/
server_input.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
#
# Server code for input panel
#
# First create a reactive function that changes over time
# (depending on user input)
input_reactive <- reactive({
# Check if example is selected, or if not then ask to upload a file.
validate(
need(input$input_source == "example_data" | !is.null(input$upload_file),
message = "Please select a file")
)
# input$upload_file will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns.
in_file <- input$upload_file
# Read data
if(input$input_source == "example_data"){
# upload example data
expr_data <- read.csv("data/TPM-17c-27c-average_misexpressed.csv")
return(expr_data)
} else if(input$input_source == "upload_data"){
# if uploading data
if (!is.null(in_file)) {
expr_data <- read.table(in_file$datapath,
header = input$header,
sep = input$sep)
validate(
need(ncol(expr_data) > 1,
message = "File appears to be one column. Check that you chose the right separator.")
)
return(expr_data)
} else{
return(NULL)
}
}
})
# This is triggered whenever the input_reactive object changes
observeEvent(input_reactive(), {
output$countdataDT <- renderDataTable({
tmp <- input_reactive()
if (!is.null(tmp)) tmp
})
})