/
server.R
158 lines (110 loc) · 4.12 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
156
157
158
function(input, output, session) {
selectedUnivData <- reactive({
if ( input$university == 'All' )
return(data)
data %>%
filter(University %in% input$university)
})
select_metrics <- reactive({
# Are there columns that are all NA?
all_na_cols <- apply(selectedUnivData(), 2, function(x) all(is.na(x)));
cols_with_all_na <- names(all_na_cols[all_na_cols>0]);
# Exclude these from the metrics vector so that they cannot be selected
new_metrics <- setdiff(metrics_select, cols_with_all_na)
new_metrics
})
# Update the selection of metrics in the UI if necessary
observe({
updateSelectInput(session, "xc",
choices = as.list(select_metrics()),
selected = "Score")
updateSelectInput(session, "yc",
choices = as.list(select_metrics()),
selected = "Twitter")
})
output$plot <- renderggiraph({
xc <- as.name(input$xc)
yc <- as.name(input$yc)
scx <- as.name(input$scx)
scy <- as.name(input$scy)
df <- selectedUnivData()
nr_unis <- length(unique(df$University))
c <- ifelse(nr_unis==1, "OpenAccess", "University")
legend_title <- c
gg_point <- ggplot(df,
aes_q(x = xc,
y = yc,
size = df$OA,
colour = df[[c]],
data_id = df$Title,
tooltip = df$Title)) +
labs(color=legend_title) +
scale_x_continuous(trans=scx) +
scale_y_continuous(trans=scy) +
geom_point_interactive(alpha = 0.5, na.rm = TRUE) +
scale_size(guide = "none")
ggiraph(code = {print(gg_point)},
selection_type = "multiple",
width_svg = 8, height_svg = 8,
hover_css = "fill:yellow",
tooltip_extra_css = tooltip_css,
tooltip_offx = 20, tooltip_offy = -10,
zoom_max = 3)
})
selected_state <- reactive({
input$plot_selected
})
observeEvent(input$reset, {
session$sendCustomMessage(type = 'plot_set', message = character(0))
})
output$sel <- renderTable({
sel_df <- selectedUnivData()
out <- sel_df[sel_df$Title %in% selected_state(),
c("Link", "Title", "University", "Journal", "OpenAccess", "Authors", "Score")]
if( nrow(out) < 1 ) return(NULL)
row.names(out) <- NULL
out
}, sanitize.text.function = function(x) x)
output$nrofitemswithmetrics <- renderValueBox({
valueBox(
"Items with metrics",
nrow(selectedUnivData()),
icon = icon("calculator"),
color = "yellow"
)
})
output$maxaltmetrics <- renderValueBox({
valueBox(
"Top Altmetric score",
max(selectedUnivData()$Score, na.rm = TRUE),
icon = icon("spinner"),
color = "green",
href = selectedUnivData()[selectedUnivData()$Score %in% max(selectedUnivData()$Score, na.rm = TRUE), "href"][1]
)
})
output$maxtwitter <- renderValueBox({
valueBox(
"Top Twitter score",
ifelse(is.finite(max(selectedUnivData()$Twitter, na.rm = TRUE)), max(selectedUnivData()$Twitter, na.rm = TRUE), "N/A"),
icon = icon("twitter"),
color = "light-blue",
href = selectedUnivData()[selectedUnivData()$Twitter %in% max(selectedUnivData()$Twitter, na.rm = TRUE), "href"][1]
)
})
output$maxmendeley <- renderValueBox({
valueBox(
"Top Mendeley score",
ifelse(is.finite(max(selectedUnivData()$Mendeley, na.rm = TRUE)), max(selectedUnivData()$Mendeley, na.rm = TRUE), "N/A"),
icon = icon("line-chart"),
color = "fuchsia",
href = selectedUnivData()[selectedUnivData()$Mendeley %in% max(selectedUnivData()$Mendeley, na.rm = TRUE), "href"][1]
)
})
# Datatable
output$datatable <- DT::renderDataTable({
totable <- selectedUnivData()
totable <- totable %>%
select(-href, -OA)
}, escape = FALSE, options = list(scrollX = T)
)
}