-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.R
executable file
·31 lines (28 loc) · 1.42 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
# Instantiate our N-Gram Prediction Engine:
source("./predictionEngine.R")
########################################################################################################################
#
# This function handles text input from the web client
# It takes the desired text and runs it through the predition engine and renders text in the web client
# @param input String
# @param output String
# @return Null
#
########################################################################################################################
shinyServer(function(input, output)
{
# Reactive listens to the web client for input change and 'reacts':
wordPrediction <- reactive({
# Get the new text input:
text <- input$text
# Clean it for prediction purposes:
textInput <- cleanInput(text)
# Get the length of the string:
wordCount <- length(textInput)
# Run the text input through the N-Gram Prediction engine:
wordPrediction <- nextWordPrediction(wordCount,textInput)})
# Tell the web client to output the predicted word:
output$predictedWord <- renderPrint(wordPrediction())
# Also tell the web client to print what was entered as a sanity check:
output$enteredWords <- renderText({ input$text }, quoted = FALSE)
})