-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
81 lines (68 loc) · 3.43 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
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
library(shiny)
library(bslib)
library(dplyr)
library(stringr)
source('Code/0_filter_moves_df.R')
source('Code/1_find_framekill.R')
source('Code/2_format_output.R')
source('Code/3_create_output_string.R')
# Get the character dropdown list options
moves_df <- readRDS('Data/rds_files/moves_df.rds')
characters <- unique(moves_df$character)
characters <- characters[!(characters == 'common')]
charlist <- list()
for (charname in characters) {
if (charname == 'aki') {
charlist[['A.K.I.']] <- 'aki'
} else if (charname == 'deejay') {
charlist[['Dee Jay']] <- 'deejay'
} else {
newname <- paste0(toupper(substring(charname, 1, 1)), substring(charname, 2, str_length(charname)))
charlist[[newname]] <- charname
}
}
# Define server logic ----
server <- function(input, output, session) {
# The character selection dropdown
output$selectOut <- renderPrint({ input$character_selection })
# The moves dropdown, which changes with the character selection dropdown
# Whatever is inside `observeEvent()` will be triggered each time the first
# argument undergoes a change in value.
observeEvent(input$character_selection,
{
moves_df <- readRDS('Data/rds_files/moves_df.rds')
new_moves_df <- filter_moves_df(input$character_selection, moves_df)
new_moves_inputs <- new_moves_df$input
new_moves_names <- new_moves_df$name
selectionlist <- list()
for (i in 1:length(new_moves_inputs)) {
inputstring <- new_moves_inputs[i]
namestring <- new_moves_names[i]
toshow <- paste0(inputstring, ' (', namestring, ')')
selectionlist[[toshow]] <- inputstring
}
updateSelectizeInput(session, inputId = "move_to_hit_selector",
choices = selectionlist)
})
# Get them to input how plus they are
# Whenever a new move is selected, we recalculate the framekills and render the output
# TODO: There should probably be a button here to update the result, so observe the button instead
observeEvent(input$action,
{
moves_df <- readRDS('Data/rds_files/moves_df.rds')
moves_df <- filter_moves_df(input$character_selection, moves_df)
framekill_list <- find_framekill(input$character_selection, input$plus_amount,
input$move_to_hit_selector, moves_df)
if (length(framekill_list) != 0) {
output_list <- format_output(input$character_selection, input$plus_amount,
input$move_to_hit_selector, moves_df, framekill_list)
text_to_render <- create_output_string(output_list)
} else {
text_to_render <- paste0('No framekills found for ',
input$character_selection, "'s ",
input$move_to_hit_selector,
' when you are +', input$plus_amount)
}
output$output_framekill <- renderText({ text_to_render })
})
}