-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheurovisionR.R
55 lines (40 loc) · 1.8 KB
/
eurovisionR.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
library(shiny)
countries <- c('Austria', 'Estonia', 'Cyprus', 'Lithuania', 'Israel', 'Czech republic', 'Bulgaria',
'Albania', 'Finland', 'Ireland', 'Portugal', 'United Kingdom', 'Spain', 'Germany', 'France',
'Italy','Serbia', 'Moldova', 'Hungary', 'Ukraine', 'Sweden', 'Australia', 'Norway', 'Denmark', 'Slovenia', 'The Netherlands')
# Define UI
ui <- fluidPage(
# App title ----
headerPanel("Eurovision sweepstake generator"),
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for variable to plot against mpg ----
sliderInput("n_countries", "Number of countries per viewer:",
min = 1, max = 5,
value = 1),
textInput('viewers', 'Enter the viewers names separated by commas', "Chad, Eric, Elon, Donald, Huw", width = '800px')
),
# Main panel for displaying outputs ----
mainPanel(
print("Give the names of the people at your party, we'll tell you who they should support."),
DT::dataTableOutput("mytable"),
print("This code uses the names input to allocate a random non-overlapping subset of the potential countries to each viewer\nCode available at https://github.com/hemprichbennett/eurovisionR")
)
)
# Define server logic to give output ----
server <- function(input, output) {
output$mytable <- DT::renderDataTable({
viewers <- strsplit(input$viewers, split = ',')[[1]]
viewers <- gsub(' ', '', viewers)
rooting_for <- list()
for(i in 1:length(viewers)){
viewer <- viewers[i]
nums <- sample(1:length(countries), input$n_countries)
rooting_for[[viewer]] <- countries[nums]
countries <- countries[-nums]
}
roots_df <- as.data.frame(rooting_for)
print(roots_df)
})
}
shinyApp(ui, server)