-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubs2.qmd
126 lines (99 loc) · 2.96 KB
/
pubs2.qmd
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
---
title: "pubs2"
format: html
server: shiny
---
```{r}
#| include: false
library(dplyr)
library(purrr)
# Get all PSI CRISTIN employees
resp <- httr2::request("https://api.cristin.no/") |>
httr2::req_url_path_append("v2/persons") |>
httr2::req_url_query(parent_unit_id="185.17.5.0",
per_page=1000) |>
httr2::req_perform()
persons <- httr2::resp_body_json(resp) |>
lapply(as_tibble) |>
bind_rows() |>
arrange(first_name, surname) |>
mutate(
name = paste(first_name, surname),
n = row_number()
) |>
select(-url)
readr::write_tsv(persons, here::here("data/cristin.tsv"))
resp <- httr2::request("https://api.cristin.no/") |>
httr2::req_url_path_append("v2/persons") |>
httr2::req_url_path_append(persons$cristin_person_id[52]) |>
httr2::req_perform()
httr2::resp_body_json(resp)
resp <- httr2::request("https://api.cristin.no/") |>
httr2::req_url_path_append("v2/persons") |>
httr2::req_url_path_append(persons$cristin_person_id[52]) |>
httr2::req_url_path_append("results") |>
httr2::req_perform()
result <- httr2::resp_body_json(resp)
tibble(
title = result %>%
pluck("title", "en"),
year_published = result$year_published,
journal_name = result %>%
pluck("journal", "name"),
contributors = result %>%
pluck("contributors", "preview") %>%
map(~ paste(.x$first_name, .x$surname, collapse = ", ")) %>%
toString(),
doi = result %>%
pluck("links") %>%
map_chr(~ if (.x$url_type == "DOI") .x$url else NA)
)
# for(k in 95:nrow(persons)){
# cli::cli_inform("{k}. {persons$name[k]}")
# persons$gid[k] <- scholar::get_scholar_id(
# last_name = URLencode(persons$surname[k]),
# first_name = URLencode(persons$name[k])
# )
# Sys.sleep(2)
# }
```
```{r}
selectInput("author_name",
"Select author",
setNames(
persons$cristin_person_id,
persons$name
))
textOutput("result_output")
```
```{r}
#| context: server
library(dplyr)
# Get all PSI CRISTIN employees
resp <- httr2::request("https://api.cristin.no/") |>
httr2::req_url_path_append("v2/persons") |>
httr2::req_url_query(parent_unit_id="185.17.5.0",
per_page=1000) |>
httr2::req_perform()
persons <- httr2::resp_body_json(resp) |>
lapply(as_tibble) |>
bind_rows() |>
mutate(
name = paste(first_name, surname)
) |>
arrange(name)
observeEvent(input$author_name, {
author <- filter(persons,
cristin_person_id == input$author_name)
get_cached_google_scholar_info <- memoise::memoise(
scholar::get_scholar_id(
last_name = URLencode(author$surname),
first_name = URLencode(author$name)
)
)
print(get_cached_google_scholar_info)
# Replace the following line with your code to fetch Google Scholar information
result <- paste("Fetching information for", author$name, input$author_name)
output$result_output <- renderText(result)
})
```