forked from SimonGoring/RegularExpressionR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
44 lines (32 loc) · 1.19 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
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dplyr)
shinyServer(function(input, output) {
text_file <- readr::read_lines("data/raw_file.txt")
output$formattedText <- renderText({
cat(input$expression, '\n')
if(nchar(input$expression)> 1 & !input$expression %in% c("h1", "h2")) {
expr <- paste0("(",input$expression,")")
replaced <- text_file %>%
stringr::str_replace_all(expr,
'<span style="background:#FFFF00">\\1</span>') %>%
paste0(collapse = "<br>") %>%
stringr::str_replace("(A Short Story)<br>",
'<h1>\\1</h1>') %>%
stringr::str_replace("(References)<br>",
'<h2>\\1</h2>')
} else {
replaced <- text_file %>%
paste0(collapse = "<br>") %>%
stringr::str_replace("(A Short Story)<br>",
'<h1>\\1</h1>') %>%
stringr::str_replace("(References)<br>",
'<h2>\\1</h2>')
}
return(replaced)
})
})