我想创建一个带有两个选项卡的 ShinyApp,每个选项卡中都有一个需要回答的问题。如果用户事先正确回答了第一个问题,则用户应该只看到带有第二个问题的第二个选项卡。如果用户之前在“问题 1”选项卡中正确回答了第一个问题,是否有可能仅显示“问题 2”选项卡?
我创建了一个最小的示例,但我没有设法隐藏选项卡二。
library(shiny)
ui <- shinyUI(pageWithSidebar(
headerPanel("Header"),
sidebarPanel(
conditionalPanel(
condition = "input.tabselected ==1",
sliderInput(
inputId = "slider1",
label = "Slider 1",
min = 0,
max = 1,
value = 0.5
),
selectInput(
inputId = "quiz1",
label = " Right or wrong",
selected = NULL,
choices = c("Right",
"Wrong")
),
conditionalPanel(
"input.quiz1 === 'Right'",
paste0("Feedback: Right"),
actionButton("Tab2", label = "Next Question")
),
conditionalPanel(
"input.quiz1 === 'Wrong'",
paste0("Feedback: Wrong")
),
conditionalPanel(
condition = "input.tabselected ==2",
sliderInput(
inputId = "slider2",
label = "Slider 2",
min = 0,
max = 1,
value = 0.5
),
selectInput(
inputId = "quiz2",
label = "True or false",
selected = NULL,
choices = c("false",
"true")
),
conditionalPanel(
"input.quiz2 === 'true'",
paste0("Feedback: Right answer")
),
conditionalPanel(
"input.quiz2 === 'false'",
paste0("Feedback: Wrong answer")
) ) ),
mainPanel(
tabsetPanel(
type = "tabs",
tabPanel(
"Question 1",
titlePanel("Description question 1"),
value = "1"
),
tabPanel(title = "Question 2" ,
value = "2",
conditionalPanel("input.quiz1 === 'Right'",
titlePanel("Description question 2")
)
),
id = "tabselected"
))))
server = function(input, output, session) {
observeEvent(input$Tab2, {
updateTabsetPanel(session, "tabselected",
selected = "2")
})
}
shinyApp(ui = ui, server = server)