-
Notifications
You must be signed in to change notification settings - Fork 0
/
sightwords.Rmd
93 lines (75 loc) · 2.55 KB
/
sightwords.Rmd
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
---
title: Sight Words
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r words}
term1 = c("I","am","at","in","a","is","on","it","up","can","mum","dad","us","an","boy","girl","to","my","with","you","no","so","he","she","be","go","the","like")
term2 = c("me","by","we","and","of","this","was","went")
week = c("see","get","do","said")
getSightWords <- function(wordlist){
if(wordlist == "Term 1"){ return(term1) }
if(wordlist == "Term 2"){ return(c(term2,week)) }
if(wordlist == "This week"){ return(week) }
return(c(term1,term2,week))
}
```
```{r shinyapp}
shinyApp(
ui = fluidPage(
#numericInput("num", label = "Make changes", value = 1),
sidebarLayout(
sidebarPanel(
selectInput("wordlist","Word list:",c("All","Term 1","Term 2","This week")),
actionButton("update" ,"New word", icon("refresh"),
class = "btn btn-primary"),
helpText("When you click the button above, you should see",
"a new sight word, right:")
),
mainPanel(
#verbatimTextOutput("value"),
htmlOutput("htmlword"),
helpText("Now type the sight word in the box below:"),
textInput("yourturn","Your turn:"),
htmlOutput("assess")
)
)
),
server = function(input, output, session) {
newWord <- reactiveVal("me")
oldWord <- reactiveVal("me")
observeEvent(input$update,{
updateTextInput(session, "yourturn", value="")
})
observeEvent(input$yourturn,{
oldWord(newWord())
})
output$htmlword <- renderUI({
input$update
sightwords = getSightWords(input$wordlist)
isolate({
newWord(sightwords[as.integer(runif(1,1,length(sightwords))+0.5)])
})
isolate(HTML(paste0("<p><font size=36 color=\"blue\">", newWord(), "</font></p><hr>")))
# isolate(HTML(paste0("<p><font size=36 color=\"blue\">", sightwords[as.integer(runif(1,1,length(sightwords))+0.5)], "</font></p><hr>")))
})
output$assess <- renderUI({
attempt = tolower(input$yourturn)
myword = tolower(newWord())
if(attempt == myword){
HTML("<p><font size=36 color=\"green\">Yes!</font></p><hr>")
}else{
if(input$yourturn == ""){
HTML("<p><font size=24 color=\"grey\">Have a go!</font></p><hr>")
}else{
HTML("<p><font size=36 color=\"red\">?</font></p><hr>")
}
}
})
}
)
#!# Add a box to enter the word and make assess whether it matches
```