-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
125 lines (121 loc) · 3.87 KB
/
server.R
File metadata and controls
125 lines (121 loc) · 3.87 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
library(shiny)
library(survminer)
library(survival)
library(readxl)
library(purrr)
library(tidyr)
library(dplyr)
library(readr)
shinyServer(function(input, output) {
v <- reactiveValues(data = NULL)
observeEvent(input$Run, {
v$data <- read_delim(file = input$file5, delim = "\t") %>%
dplyr::mutate(across(everything(), ~ replace_na(.x, 0)))
})
NCOL <- reactive({
ncol(v$data)
})
file3 <- reactive({
purrr::map_df(2:NCOL(), ~ tibble(time = rep(dplyr::pull(v$data, 1), dplyr::pull(v$data, .x)), event = 1, group = names(v$data)[.x]))
})
nms <- reactive({
names(v$data)[-1] %>% as.vector()
})
table1 <- reactive({
FormatPv <- function(i) {
c <- file3() %>%
dplyr::filter(group == nms()[1] | group == nms()[i]) %>%
surv_fit(Surv(time, event) ~ group, data = .) %>%
surv_pvalue(.) %>%
dplyr::pull(2) %>%
ROUND(3)
if (c < 0.0001) {
c <- "< 0.0001"
}
return(as.character(c))
}
ref <- file3() %>%
dplyr::filter(group == names(v$data)[2]) %>%
dplyr::pull(1) %>%
mean()
d <- file3() %>%
dplyr::group_by(group) %>%
dplyr::mutate(group = factor(group, levels = nms())) %>%
summarise(
meanse = paste0(ROUND(mean(time), 3), "±", ROUND(SE(time), 3)),
PLC = ROUND((mean(time) / ref - 1) * 100, 3), N = n()
) %>%
dplyr::mutate(pv = c("", map_chr(2:(NCOL() - 1), FormatPv)), .before = "PLC")
d[[4]][1] <- ""
d
})
plot1 <- reactive({
p1 <- ggsurvplot(surv_fit(Surv(time, event)~group, data = file3()),
axes.offset = F,
xlim = c(0, ceiling(max(dplyr::pull(file3(),1))/5)*5+1),
xlab = expression("Days at 20" ~ degree * C),
ylab = "Fraction survival",
break.x.by = 10, # 设置x轴刻度间距
break.y.by = .2, # 设置y轴刻度间距
legend = "none",
size = 1, # line size,
pval.size = 3,
palette = c("black", "red", "green", "brown", "blue", "pink", "purple","salmon"), # line colours
pval = ifelse(NCOL() > 3, F, T)
)
p1$plot <- p1$plot %+%
theme(
axis.title.x = element_text(size = 10),
axis.title.y = element_text(size = 10),
axis.text.x = element_text(size = 8),
axis.text.y = element_text(size = 8),
# plot.margin = margin(.5,.5,.5,.5,unit = "cm"),
axis.line = element_line(size = .5),
# axis.ticks = element_text(size = 1),
axis.ticks.length = unit(.1, "cm"),
text=element_text("sans")
)
p1$plot
})
# main output
output$table1 <- renderTable(
{
if (is.null(v$data)) {
return()
}
table1()
},
align = "c"
)
output$plot1 <- renderPlot({
if (is.null(v$data)) {
return()
}
plot1()
})
# Download
output$downspss <- downloadHandler(
filename = function() {
paste0(nms()[1], ".spss.txt")
},
content = function(file) {
write_delim(file3(), file, delim = "\t")
}
)
output$downtable <- downloadHandler(
filename = function() {
paste0(nms()[1], ".txt")
},
content = function(file) {
write_delim(table1(), file, delim = "\t")
}
)
output$downplot <- downloadHandler(
filename = function() {
paste0(nms()[1], ".pdf")
},
content = function(file) {
ggsave(plot=plot1(),file,width = 50,height = 50,units="mm")
}
)
})