-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdocs.qmd
More file actions
265 lines (237 loc) · 6.68 KB
/
docs.qmd
File metadata and controls
265 lines (237 loc) · 6.68 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
---
title: "Data documentation"
---
Click on each dataset's name to see its description, license, citation, and link to its original source. Code used to create these data can be found [here](https://github.com/ben-domingue/irw/tree/main/data).
```{=html}
<div class="panel-tabset-container">
<button onclick="toggleTabset()">To cite using IRW's R package</button>
<div class="panel-tabset" style="display: none;">
<div class="r-command">
<p>> <code>irw_save_bibtex("gilbert_meta_48")</code></p>
</div>
<div class="bibtex-entry">
<pre>
@misc{gilbert_meta_48,
doi = {10.7910/DVN/3SF36J},
url = {https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/3SF36J},
author = {Cárdenas, Sergio and Evans, David K.},
keywords = {Social Sciences},
title = {Replication Data for: Parent Training and Child Development at Low Cost? Evidence from a Randomized Field Experiment in Mexico},
publisher = {Harvard Dataverse},
year = {2023}
}
</pre>
</div>
</div>
</div>
<style>
/* Style for the toggle button */
.panel-tabset-container button {
margin-bottom: 10px;
padding: 5px 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.panel-tabset-container button:hover {
background-color: #0056b3;
}
/* Style for the panel content */
.panel-tabset {
display: none; /* Hide by default */
border: 1px solid #ddd;
padding: 10px;
border-radius: 4px;
background: #f9f9f9;
font-family: 'Courier New', Courier, monospace;
}
/* Style for the R command line */
.r-command {
margin-bottom: 15px;
color: #333;
font-size: 14px;
}
.r-command p {
margin: 0;
padding: 5px;
background-color: #f3f3f3;
border-left: 3px solid #007BFF;
font-family: monospace;
}
/* Style for the BibTeX block */
.bibtex-entry pre {
background-color: #f3f3f3;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-family: monospace;
font-size: 14px;
overflow-x: auto;
}
</style>
<script>
function toggleTabset() {
const tabset = document.querySelector('.panel-tabset');
tabset.style.display = (tabset.style.display === 'none' || tabset.style.display === '') ? 'block' : 'none';
}
</script>
```
```{r}
library(dplyr)
library(purrr)
library(readr)
library(stringr)
library(glue)
library(redivis)
biblio <- redivis$user("bdomingu")$dataset("irw_meta:bdxt:latest")$table("biblio:qahg")$to_tibble()
# Load datasets
data_index <- biblio |>
rename(dataset = `table`, url = URL__for_data_, license = `Derived_License`,
description = Description, reference = Reference_x, doi = DOI__for_paper_) |>
mutate(dataset = str_remove(dataset, ".R.ata$")) |>
arrange(dataset)
```
```{=html}
<input type="text" id="searchBar" placeholder="Search datasets..." style="width: 100%; padding: 10px; margin-bottom: 20px; font-size: 16px;">
<script>
function searchDatasets() {
var input = document.getElementById('searchBar');
var filter = input.value.toLowerCase();
var items = document.getElementsByClassName('dataset-item');
for (var i = 0; i < items.length; i++) {
var text = items[i].textContent || items[i].innerText;
items[i].style.display = text.toLowerCase().indexOf(filter) > -1 ? '' : 'none';
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getCitation(bibtex, buttonId, targetId) {
const button = document.getElementById(buttonId);
button.disabled = true;
button.textContent = 'Loading...';
try {
await sleep(100); // Small delay for UI feedback
const target = document.getElementById(targetId);
const container = document.createElement('div');
container.className = 'citation-container';
const citationText = document.createElement('pre');
citationText.className = 'citation-pre';
citationText.textContent = bibtex;
const copyButton = document.createElement('button');
copyButton.className = 'copy-button';
copyButton.innerHTML = '📋 Copy';
copyButton.onclick = () => {
navigator.clipboard
.writeText(bibtex)
.then(() => {
copyButton.innerHTML = '✓ Copied!';
setTimeout(() => (copyButton.innerHTML = '📋 Copy'), 2000);
})
.catch(() => (copyButton.innerHTML = '❌ Error'));
};
target.innerHTML = '';
container.appendChild(citationText);
container.appendChild(copyButton);
target.appendChild(container);
target.style.display = 'block';
} catch (error) {
console.error('Error displaying citation:', error);
const target = document.getElementById(targetId);
target.textContent = 'Error displaying citation. Please try again.';
target.style.display = 'block';
} finally {
button.disabled = false;
button.textContent = 'Get BibTex';
}
}
document.getElementById('searchBar').addEventListener('input', searchDatasets);
</script>
<style>
.citation-container {
position: relative;
margin-top: 10px;
padding: 10px;
background-color: #f5f5f5;
border-radius: 4px;
min-height: 50px;
}
.citation-pre {
font-family: monospace;
white-space: pre-wrap;
word-wrap: break-word;
margin: 0;
padding: 20px 10px 10px 10px;
max-width: 100%;
overflow-x: auto;
}
.copy-button {
position: absolute;
top: 5px;
right: 5px;
background-color: #ffffff;
border: 1px solid #dddddd;
border-radius: 4px;
padding: 4px 8px;
cursor: pointer;
font-size: 12px;
z-index: 1;
}
.copy-button:hover {
background-color: #f0f0f0;
}
.citation-button {
background-color: #007bff;
color: white;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.citation-button:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
</style>
```
```{r}
#| results: asis
el <- function(ds) {
lic <- if (ds$license != "") glue("({ds$license})") else ""
bibtex <- ds$BibTex # Use BibTex column directly
escaped_bibtex <- if (!is.na(bibtex) && bibtex != "") gsub("'", "\\\\'", bibtex) else ""
citation_button <- if (escaped_bibtex != "") {
button_id <- paste0("cite-button-", make.names(ds$dataset))
target_id <- paste0("cite-text-", make.names(ds$dataset))
glue(
'<button id="{button_id}" class="citation-button" onclick="getCitation(`{escaped_bibtex}`, \'{button_id}\', \'{target_id}\')">
Get BibTex
</button>
<div id="{target_id}" class="citation-text"></div>'
)
} else ""
glue(
"
::: {{.g-col-4 .dataset-item}}
::: {{.callout-note collapse='true'}}
## {ds$dataset}
{ds$description} {lic} [[link]]({ds$url})
<i>{ds$reference}</i>
{citation_button}
:::
:::
"
)
}
els <- transpose(data_index) |> map(el) |> paste(collapse = "\n")
cat(glue(
"
::: {{.grid}}
{els}
:::
"
))
```