Hi everyone,
I just started learning R to program an experiment for my thesis, so sorry in advance for asking what are probably super basic questions.
I want to build a survey (in German) consisting of multiple pages.
On the page HSVG1
I would like to include two barplots as visualization of options two choose from with corresponding actionButtons, and a sliderInput below (already included).
I am wondering how to add two horizontal barplots to the page in a way that they appear above the action buttons G1A
and G1B
. I tried adding a vector (10,20) to use for the height of the plot, but it always returned an error (Text to be written must be a length-one character vector).
Pls find the code I came up with so far below.
Help would be much appreciated - I can´t really find a solution on my own!
library(shiny); library(shinyjs)
###################################################
#ui
###################################################
ui <- (htmlOutput("page"))
useShinyjs()
###intro
intro <- function(...) {
div(class = 'container', id = "intro",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Startseite"),
p("Platzhalter"),
br(),
actionButton("W1", W)
))
}
###declaration of consent
decl <- function(...) {
div(class = 'container', id = "decl",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Einwilligung zur Teilnahme"),
p("Platzhalter"),
br(),
radioButtons("Einwilligung",label = NULL, choices = c("Ich stimme zu","Ich stimme nicht zu")),
actionButton("W2", W)
))
}
###explanation HSV
expl1 <- function(...) {
div(class = 'container', id = "expl1",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Einleitung Teil 1"),
p("Platzhalter"),
br(),
actionButton("W3", W)
))
}
###HSV
#G1
HSVG1 <- function(...) {
div(class = 'container', id = "intro",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Welche Option bevorzugen Sie?"),
p(G1),
br(),
actionButton("G1A", A),
actionButton("G1B", B),
actionButton("G1eq", C),
sliderInput("S1", D, 10, 20, 15, step = 0.1)
))
}
###conclusive elicitation
concl <- function(...) {
div(class = 'container', id = "concl",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Abschliessende Erhebung"),
p("Bitte beantworten Sie zuletzt die folgenden Fragen."),
br(),
selectInput("Geschlecht","Mein Geschlecht ist", c("maennlich","weiblich","divers")),
numericInput("Alter","Mein Alter ist",value = NULL),
actionButton("W4", W)
))
}
###outro
outro <- function(...) {
div(class = 'container', id = "outro",
div(class = 'col-sm-2'),
div(class = 'col-sm-8',
h1("Abschluss"),
p("Platzhalter"),
br(),
textInput("Email","Email"),
actionButton("Senden", "Senden"),
actionButton("end", "Beenden")
))
}
render_page <- function(...,f, title = "Test") {
page <- f(...)
renderUI({
fluidPage(page, title = title)
})
}
###################################################
###server
###################################################
server <- function(input, output){
#intro
output$page <- render_page(f = intro)
#declaration of consent
observeEvent(input$W1, {
output$page <- render_page(f = decl)
})
#explanation HSV
observeEvent(input$W2, {
if (input$Einwilligung == "Ich stimme zu") output$page <- render_page(f = expl1)
})
#HSV
observeEvent(input$W3, {
output$page <- render_page(f = HSVG1)
})
#outro
observeEvent(input$W4, {
output$page <- render_page(f = outro)
})
#end
observeEvent(input$end, {
stopApp()
})
}
###################################################
###run
###################################################
shinyApp(ui = ui, server = server)