I am sorry for the confusing title but I really cannot figure a better one. I hope I can express my problem better with the below example codes and my explanation.
I am trying to make a shiny app, and I need to collect basic information of subjects in the beginning, including age, gender, and their subject ID, which is a 5-digits number. I have checked the below codes many times, and it always shows that the conditions about age and gender work well. Besides, since the subject ID is a 5-digits number, I have set the condition as "input$subject_ID > 99999| input$subject_ID < 9999". However, the subject ID condition is not effective. For example, when I entered 12312 which should fulfill the condition, the app does not update the page as it should do.
Can someone tell me what's wrong with this?
Best, J-L
library(shiny)
library(shinyjs)
ui <- fluidPage(id="main",title="test",useShinyjs(),
navlistPanel(id="main",widths = c(1, 11),
tabPanel("Info",
fluidRow(radioButtons("gender",label="Your gender",choiceNames=c("Please choose: ","Female","Male"), choiceValues=c(2,0,1),selected=2,inline=T)),
fluidRow(textInput( "age", label="Your age")),
fluidRow(textInput( "subject_ID", label="Your subject ID obtained from last part")),
fluidRow(actionButton( "submit_info", label="Submit, and next page"))
),
tabPanel("Video",
fluidRow()
)))
server <- function(input, output, session) {
hide(selector = "#main li a[data-value=Video]")
observeEvent(input$submit_info,{
if (input$gender == 2 | 18 > input$age | input$age > 80 | input$subject_ID > 99999| input$subject_ID < 9999){
showModal(modalDialog(
title = "Message",
"You have not indicated your age, gender or subject ID (correctly). Please make sure you answer these three infomation questions before you continue.",easyClose=T,footer = modalButton("OK")))
}else{
show(selector = "#main li a[data-value=Video]");
updateNavlistPanel(session, "main", "Video");
hide(selector = "#main li a[data-value=Info]")
}})
}
shinyApp(ui,server)
Aucun commentaire:
Enregistrer un commentaire