-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.R
86 lines (74 loc) · 2.11 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
library(shiny)
library(shinydashboard)
shinyServer(function(input, output, session) {
tab_list <- NULL
# ____________________________________________________________________________
# OUTPUTS ####
reactiveFiles = reactive({
file_data <- scan_repos()
return(file_data)
})
files = reactive({
filesData <- reactiveFiles()
files <- with(filesData, split(file, title))
return(files)
})
output$repos <- renderUI({
sidebarMenu(
id = "repotabs",
lapply(names(files()), function(i) {
menuItem(i,
tabName = i,
icon = icon("chevron-right")
)
})
)
})
output$intro <- renderUI({
includeMarkdown("README.md")
})
output$ui_line <- renderUI({
## using renderUI here because Knitr will not create a slider
tagList(
sliderInput("nr_points", "", min = 10, max = 100, value = 50),
renderPlot({
nr <- if (is.null(input$nr_points)) 2 else input$nr_points
plot(1:nr, rnorm(nr))
})
)
})
# ____________________________________________________________________________
# EVENTS ####
observeEvent(input$searchButton, {
if(input$searchButton > 0L) {
isolate({
file_data <- reactiveFiles()
file_data <- file_data %>% dplyr::filter(grepl(input$searchText, title))
return(file_data)
})
}
})
# Render Markdown Files In New Tab
observeEvent(input$repotabs, {
mdinput <- input$repotabs
mdfile <- reactiveFiles()$file[reactiveFiles()$title == mdinput]
tab_title <- reactiveFiles()$title[reactiveFiles()$title == mdinput]
if (!(tab_title %in% tab_list)) {
appendTab(
inputId = "tabs",
tabPanel(
tab_title,
renderUI(displayMarkdown(mdfile))
)
)
tab_list <<- c(tab_list, tab_title)
}
updateTabsetPanel(session, "tabs", selected = tab_title)
})
# Remove tabs
observeEvent(input$remove, {
tab_list %>%
walk(~removeTab("tabs", .x))
tab_list <<- NULL
})
})