-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
73 lines (65 loc) · 2.16 KB
/
server.R
File metadata and controls
73 lines (65 loc) · 2.16 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(readxl)
mots <- read_excel("data/mots.xlsx")
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
r <- reactiveValues(afficherReponse = FALSE,
urlSon = "")
choixMode <- reactive({
r$afficherReponse <- FALSE
if(input$question == "Son -> Français"){
r$pathFichier <- sprintf("%s.mp3", randomVals())
}else{
r$pathFichier <- sprintf("%s.mp3", -1)
}
switch(input$question,
"Français -> Pinyin" = c(4),
"Pinyin -> Français" = c(3),
"Chinois -> Français" = c(2),
"Son -> Français" = c(-1))
})
randomVals <- eventReactive(input$nouveauMot, {
r$afficherReponse <- FALSE
sample.int(nrow(mots), size = 1)
}, ignoreNULL = FALSE)
output$reponse <- renderText({
reponse <- paste0("<br>Le mot à trouver était :<br>",
"<font size=\"",input$size,"px\">",
paste(mots[randomVals(),-1],collapse = " = "),
"</font>")
if(r$afficherReponse){
reponse
}else{
""
}
})
observeEvent(input$playsound, {
insertUI(selector = "#playsound",
where = "afterEnd",
ui = tags$audio(src = r$pathFichier,
type = "audio/mp3", autoplay = NA, controls = NA, style="display:none;")
)
})
observeEvent(input$reponse, {
r$afficherReponse <- TRUE
})
output$motADeviner <- renderText({
#paste0("test", mot_hasard)
if(choixMode() >0){
paste0("Le mot à deviner est :<br>",
"<font size=\"",input$size,"px\">",
as.character(mots[randomVals(), choixMode()]),
"</font><br><br><br>")
}else{
""
}
})
})