-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
73 lines (61 loc) · 1.77 KB
/
app.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
library(shiny)
library(synthesisr)
library(dplyr)
library(bslib)
ui <- fluidPage(
theme = bs_theme(
version = 5,
bg = "#008080", # Teal background
fg = "white", # White text
primary = "#ffffff" # Optional: White primary components
),
titlePanel("refRandomiseR"),
sidebarLayout(
sidebarPanel(
fileInput("ris_file", "Upload RIS File", accept = ".ris"),
radioButtons("subset_type", "Subset by:",
choices = c("Percentage" = "percentage", "Number of Records" = "number")),
numericInput("subset_value", "Enter Value:", value = 10, min = 1),
actionButton("subset", "Subset Records")
),
mainPanel(
tableOutput("subset_results"),
downloadButton("download_subset", "Download Subset")
)
)
)
server <- function(input, output, session) {
records <- reactiveVal(NULL)
observeEvent(input$ris_file, {
req(input$ris_file)
# Read RIS file
ris_data <-synthesisr::read_refs(input$ris_file$datapath)
records(as.data.frame(ris_data))
})
subsetted_records <- eventReactive(input$subset, {
req(records())
data <- records()
if (input$subset_type == "percentage") {
# Subset by percentage
n <- ceiling((input$subset_value / 100) * nrow(data))
} else {
# Subset by number
n <- min(input$subset_value, nrow(data))
}
data[sample(nrow(data), n), ]
})
output$subset_results <- renderTable({
subsetted_records()
})
output$download_subset <- downloadHandler(
filename = function() {
"subset_records.ris"
},
content = function(file) {
req(subsetted_records())
ris_out <- write_refs(subsetted_records(), format = "ris", file = FALSE)
writeLines(ris_out, file)
}
)
}
shinyApp(ui, server)