-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
49 lines (38 loc) · 1.6 KB
/
server.R
File metadata and controls
49 lines (38 loc) · 1.6 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
library(shiny)
source("./model.R", local = TRUE)
shinyServer(
function(input, output, session){
prediction <- reactive({
nextWordPredictor(input$inputTxt)
})
output$words <- renderUI( {
predictWords <- prediction()
assign('savedWords', predictWords, envir=.GlobalEnv)
n <- length(predictWords)
if( n > 0 && nchar(predictWords) > 0) {
buttons <- list()
for(i in 1:n) {
buttons <- list(buttons, list(
actionButton(inputId = paste("word",i, sep = ""), label =predictWords[i])
))
}
tagList(
buttons
)
} else {
tagList("")
}
})
observeEvent(input$word1, {
updateTextInput(session, "inputTxt", value = paste(input$inputTxt, get('savedWords', envir=.GlobalEnv)[1]))
})
observeEvent(input$word2, {
updateTextInput(session, "inputTxt", value = paste(input$inputTxt, get('savedWords', envir=.GlobalEnv)[2]))
})
observeEvent(input$word3, {
updateTextInput(session, "inputTxt", value = paste(input$inputTxt, get('savedWords', envir=.GlobalEnv)[3]))
})
observeEvent(input$word4, {
updateTextInput(session, "inputTxt", value = paste(input$inputTxt, get('savedWords', envir=.GlobalEnv)[4]))
})
})