-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
155 lines (109 loc) · 4.43 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function(input, output, session) {
# When school is selected, filter data with it
schoolData <- reactive({
if ( input$school == "Aalto University" ) return(data) else data[data$parent %in% input$school, ]
})
# Update dept list of the selected school
observe(
updateSelectInput(session,
inputId = 'dept',
choices = if ( input$school == "Aalto University" ) "Select school first" else c("All", sort(unique(schoolData()$name)))
)
)
# Filter school data by dept, if selected
deptData <- reactive({
if ( is.null(input$dept) || input$dept == "Select school first" || input$dept == "All") {
return(schoolData())
}
isolate(schoolData() %>% filter(name %in% input$dept))
})
# Prepare URLs for datatable
makedata <- reactive({
totable <- deptData()
totable <- totable %>%
mutate(url = paste0("<a target='blank' href='https://doi.org/", doi, "'>", doi, "</a>"),
oa_url = ifelse(!is.na(urls),
paste0("<a target='blank' href='", urls, "'>", urls, "</a>"),
urls)) %>%
rename(oa_virta = oa) %>%
select(url, title, year, is_oa, oa_url, times_cited, wos, recent_citations, relative_citation_ratio, field_citation_ratio,
tweets, mendeley, altm_score,
authors, oa_virta, fieldcount, parent, name)
})
output$scatter <- renderPlotly({
df <- deptData()
colors <- df$color
title <- if(is.null(input$dept) || input$dept == "Select school first" || input$dept == "All") input$school
else paste0(input$school, ", ",input$dept)
p <- plot_ly(df,
type = "scatter",
x = ~get(input$xc),
y = ~get(input$yc),
mode = "markers",
colors = colors,
color = I(colors),
split = ~parent,
symbol = ~symbol,
marker = list(size = 10, opacity = 0.7),
hovertext = ~text) %>%
layout( xaxis = list( title = input$xc,
type = input$xscale),
yaxis = list( title = input$yc,
type = input$yscale),
title = title)
})
output$prop_oa <- renderValueBox({
valueBox(
"With OA full text",
ifelse(input$school == "Aalto University",
with_oa_uniquedois,
paste0(nrow(deptData()[!is.na(deptData()$urls) & !duplicated(deptData()[,1]), ]), " (",
floor(nrow(deptData()[!is.na(deptData()$urls) & !duplicated(deptData()[,1]), ]
) / nrow(deptData()[!duplicated(deptData()[,1]), ]) * 100), "% )")),
icon = icon("calculator"),
color = "yellow"
)
})
output$heatmap <- renderPlotly({
if(is.null(input$dept) || input$dept == "Select school first" || input$dept == "All")
return()
dept_data <- f_means %>%
filter(name == input$dept)
rnames <- dept_data[["field_name"]]
mat_data <- data.matrix(dept_data[,c(4:8)])
rownames(mat_data) <- rnames
plot_ly(type = "heatmap",
x = colnames(mat_data), y = rownames(mat_data), z = mat_data,
key = mat_data, source = mat_data) %>%
layout(title = paste0("Mean metrics by field in ",input$dept),
xaxis = ax, yaxis = ay,
showlegend = FALSE,
autosize = F,
width = w,
height = h,
margin = m)
})
output$datatable <- DT::renderDataTable({
dat <- datatable(makedata(),
escape = FALSE,
rownames = FALSE,
extensions = "FixedHeader",
options = list(paging = TRUE,
fixedHeader = TRUE,
autoWidth = TRUE,
scrollX = TRUE,
columnDefs = list(list(target = "_all", width = "50px"))))
return(dat)
})
output$data_dim_aalto = downloadHandler(
filename = function() {
filename = 'data_dim_aalto.csv'
},
content = function(file) {
{
write.csv(deptData(), 'temp.csv', row.names = FALSE)
file.rename('temp.csv', file)
}
}
)
}