Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 操作按钮输入后更新单选按钮_Shiny_Radio Button_Reactive_Action Button - Fatal编程技术网

Shiny 操作按钮输入后更新单选按钮

Shiny 操作按钮输入后更新单选按钮,shiny,radio-button,reactive,action-button,Shiny,Radio Button,Reactive,Action Button,我正在创建一个闪亮的应用程序,我希望我的一个标签是一个13个问题的测验/游戏。但是,我不希望同时显示所有13个问题。我想包括一个操作按钮,当用户按下时,会显示下一个问题。目前,将显示两个问题。此外,我是否需要为每个问题创建单独的操作按钮 问题2:问题1-5使用相同的绘图。问题6-13将使用不同的情节,我希望问题和情节在问题5之后都有所改变。我举了两个问题作为例子 在我的UI脚本中,我有: navbarPage( "NEO Guess Who", position = &q

我正在创建一个闪亮的应用程序,我希望我的一个标签是一个13个问题的测验/游戏。但是,我不希望同时显示所有13个问题。我想包括一个操作按钮,当用户按下时,会显示下一个问题。目前,将显示两个问题。此外,我是否需要为每个问题创建单独的操作按钮

问题2:问题1-5使用相同的绘图。问题6-13将使用不同的情节,我希望问题和情节在问题5之后都有所改变。我举了两个问题作为例子

在我的UI脚本中,我有:

navbarPage(
  "NEO Guess Who", position = "fixed-top",
 tabPanel("Quiz",
          fluidPage(
            titlePanel(h1("Do you even know us?")),
            sidebarLayout(
              sidebarPanel(
                radioButtons("q1", "Whose personality is plotted as the purple line?",
                         choices = list("Amy" = "Amy",
                                          "Claire" = "Claire",
                                          "Olivia" = "Olivia",
                                          "Shae" = "Shae",
                                          "Sharon" = "Sharon"),
                           selected = character(0)),
                           textOutput("q1text"),
                           actionButton("q1action", "Next", class = "btn-success"),
                radioButtons("q2", "Whose personality is plotted as the blue line?",
                             choices = list("Amy" = "Amy",
                                            "Claire" = "Claire",
                                            "Olivia" = "Olivia",
                                            "Shae" = "Shae",
                                            "Sharon" = "Sharon"),
                             selected = character(0))),
              mainPanel(
                plotOutput("plot7"))
             )))
         )
在服务器脚本中,我有:

  output$q1text <- renderText({
    q1 <- switch (input$q1,
      Amy = paste("Oops, the correct answer is Sharon"),
      Claire = paste("Oops, the correct answer is Sharon"),
      Olivia = paste("Oops, the correct answer is Sharon"),
      Shae = paste("Oops, the correct answer is Sharon"),
      Sharon = paste("Correct!"),
    )
  })

 observeEvent(input$q1action, {
   updateRadioButtons(session, "q1", choices = c("Amy", "Claire", "Olivia", "Shae", "Sharon"), selected = 0)
   updateRadioButtons(session, "q2", choices = c("Amy", "Claire", "Olivia", "Shae", "Sharon"), selected = 0)
 })
  # both questions are still displayed

  # no legend
  output$plot7 <-  renderPlot({
    {neo_simple <- read.csv("neo_simple.csv", header = T, sep = ",")}
    {neo_simple$domain <- factor(neo_simple$domain, levels = c("neuroticism", "extraversion", "openness", "agree", "conscient"))}
    
    {neoColors <-
        setNames( c('#a6cee3', '#b2df8a', '#fb9a99', '#fdbf6f', '#cab2d6'), 
                  levels(neo_simple$id)  )}
    
    neo_simple %>%
      ggplot(aes(x = domain, y=tscore, group = id, color = id)) +
      geom_point(size = 1.75) +
      scale_color_manual(values = neoColors) +
      geom_line(size = 1.25) +
      theme_bw() +
      ggtitle("NEO Domain Scores") +
      theme(plot.title = element_text(hjust = 0.5, size = 15))  +
      theme(text = element_text(size=rel(4.5))) +
      theme(legend.position = "none") +
      theme(plot.caption = element_text(hjust = 0, size = 14))
    
  }) 

output$q1text也许“slickR”包是一种可能的方式:

library(shiny)
library(slickR)

ui <- fluidPage(
  slickROutput("questions", width = "50%")
)

server <- function(input, output, session){
  
  output[["questions"]] <- renderSlickR({
    slickR(
      slick_list(
        radioButtons(
          "q1",
          "First question",
          choices = c("Yes", "No")
        ),
        radioButtons(
          "q2",
          "Second question",
          choices = c("True", "False")
        )
      )
    )
  })
  
}

shinyApp(ui, server)
库(闪亮)
图书馆(滑头)

非常感谢你!我真的很喜欢这个,但是在单选按钮被点击后,它不会保留我的文本。我尝试了
observeEvent(输入$questions$q1,{output$q1text