-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
55 lines (39 loc) · 1.87 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
if(.Platform$OS.type == "unix") {
source("rSource/startup.R",echo=TRUE, verbose=FALSE)
} else {
source("rSource\\startup.R",echo=TRUE, verbose=FALSE)
}
nDocs <- 3
if (!exists("sNDS")) load("shortNDS.RData")
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
s1 <- reactive({predictFromTextSmall(input$text)})
lens <- reactive({length(s1()$tdl)})
output$lens <- renderText(lens())
# s2 <- reactive({ mostLikelyNWords(5,paste(input$text,s1()$uSAD[1]))})
# output$nxt <- renderText(s2())
include <- reactive({ sapply(1:lens(), function(i) { sum(is.na(s1()$tdl[[i]])*1)==0 }) })
wordList <- reactive({s1()$tdl})
output$include <- reactive({include()})
wordListLengths <- reactive({sapply(wordList(),length)})
wordList <- reactive({s1()$tdl[include()]})
mins <- reactive({ sapply(wordListLengths(),function(w) min(10, max(w,1)))})
output$doc1 <- renderText(docNames[1])
output$doc2 <- renderText(docNames[2])
output$doc3 <- renderText(docNames[3])
# output$e1 <- renderText(exists("include()[1]")*1)
# output$e2 <- renderText(exists("include()[2]")*1)
# output$e3 <- renderText(exists("include()[3]")*1)
# #
# output$i1 <- renderText(include()[1]*1)
# output$i2 <- renderText(include()[2]*1)
# output$i3 <- renderText(include()[3]*1)
#
output$wordList1 <- reactive({if(include()[1]) {paste(wordList()[[1]][1:mins()[1]], sep=" ")} else {""}})
output$wordList2 <- reactive({if(include()[2]) {paste(wordList()[[2]][1:mins()[2]], sep=" ")} else {""}})
output$wordList3 <- reactive({if(include()[3]) {paste(wordList()[[3]][1:mins()[3]], sep=" ")} else {""}})
output$totNum <- renderText(s1()$totalNumPred)
output$plot <- renderPlot({ plotAll(s1()$adNgrams) })
output$results <- renderText({ s1()$uSAD[1:min(length(s1()$uSAD), RPTLEN)] })
output$best <- renderText({ s1()$uSAD[1] })
})