-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
139 lines (112 loc) · 3.89 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
server <- function(input, output, session) {
# show/hide app theme selector
observeEvent(input$appThemeToggle,{
if(isTRUE(input$appThemeToggle)){
CustomJS$show(id = "AppThemeSelector")
} else {
CustomJS$hide(id = "AppThemeSelector")
}
})
################################################################################################################
# Tab 1 - View ----
################################################################################################################
## enable aceEditor additional functionalities
aceAutocomplete("rmdView")
aceTooltip("rmdView")
# update Example selection
observeEvent(input$editorExampleView,{
# works
updateAceEditor(session = session, editorId = "rmdView", value = paste(readLines(file.path("R",input$editorExampleView)), collapse = "\n"), border = "flash")
}, ignoreInit = TRUE)
# update AceEditor Theme based on selection ----
observeEvent(input$aceThemeView,{
# tab 1
updateAceEditor(session = session, editorId = "rmdView", theme = input$aceThemeView)
# tab 2
# updateAceEditor(session = session, editorId = "rmd", theme = input$aceThemeView)
updateSelectInput(session = session, inputId = "aceTheme", selected = input$aceThemeView)
}, ignoreInit = FALSE)
# Knit HTML document continously RHS ----
output$knitDocView <- renderUI({
# input$eval
if (length(input$rmdView) == 0L || input$rmdView == '')
return(NULL)
HTML(
knitr::knit2html(
# text = isolate(input$rmd),
text = input$rmdView,
fragment.only = TRUE,
quiet = TRUE
),
'<script>',
'MathJax.Hub.Queue(["Typeset", MathJax.Hub]); // update MathJax expressions',
'</script>'
)
})
################################################################################################################
# Tab 2 - Create ----
################################################################################################################
## enable aceEditor additional functionalities
aceAutocomplete("rmd")
aceTooltip("rmd")
# aceAnnotate("rmd")
# observeEvent(input$editorExample,{
# # works
# updateAceEditor(session = session, editorId = "rmd", value = paste(readLines(file.path("R",input$editorExample)), collapse = "\n"), border = "flash")
# }, ignoreInit = TRUE)
# update AceEditor Theme based on selection ----
observeEvent(input$aceTheme,{
updateAceEditor(session = session, editorId = "rmd", theme = input$aceTheme)
}, ignoreInit = FALSE)
# Knit HTML document continously RHS ----
output$knitDoc <- renderUI({
# input$eval
if (length(input$rmd) == 0L || input$rmd == '')
return(NULL)
HTML(
knitr::knit2html(
# text = isolate(input$rmd),
text = input$rmd,
fragment.only = TRUE,
quiet = TRUE
),
'<script>',
'MathJax.Hub.Queue(["Typeset", MathJax.Hub]); // update MathJax expressions',
'</script>'
)
})
## Download Button Handlers
output$DownloadRmd <- downloadHandler(
filename = function() {
paste0("Blog_",Sys.Date(),".Rmd")
},
content = function(file) {
writeLines(text = input$rmd, con = file)
}
)
output$DownloadHTML <- downloadHandler(
filename = function() {
paste0("Blog_View_",Sys.Date(),".html")
},
content = function(file) {
writeLines(
text = knitr::knit2html(
text = input$rmd,
fragment.only = TRUE,
quiet = TRUE
),
con = file
)
}
)
# # auto save RMD file
# observeEvent(input$rmd,{
#
# if (length(input$rmd) == 0L || input$rmd == '')
# return(NULL)
#
# # auto save rmd file - Create Tab
# writeLines(text = input$rmd, con = file.path("R","knitExample_Create.Rmd"))
#
# }, ignoreInit = TRUE)
} # close server