2017-06-22 30 views
0

Shinyのクイズタイプのプログラムで作業しています。これは、テーブルからの回答で更新されるラジオボタンが必要です。私は以下のコードを持っていますが、ラジオボタンは更新されず、質問は変化しても答えは2、3、4、5、6のままです。なぜこれが起こっているのか、そしてこれを修正するのかについてのアイデアはありますか?R shinyラジオボタンがupdateRadioButtonsで更新されない

library(shiny) 


ui <- fluidPage(

    selectInput("numberchoice",label = "Choose an image", choices = c(1:6), selected = 1) 
    , 
    imageOutput("image") 
    , 
    radioButtons("answerchoice", "Answers", choices = c(2:6)) 

) 

server <- function(input,output,session) { 
    answers <- read.csv("~/Answers.csv") 
    questions <- read.csv("~/Answers.csv") 
    output$image <- renderImage(list(src = paste("~",".png", sep = "") 
    ,contentType = "image/png", alt = "Face"),deleteFile = FALSE) 
    eventReactive(input$numberchoice,{updateRadioButtons(session,"answerchoice",choices = questions[input$numberchoice,2:6])}) 
} 

shinyApp(ui = ui, server = server) 
+0

'selectInput'は' UIOutput() 'で構築する必要があります。次に、UI出力から 'server'関数に入る入力とともに' renderUI() 'を使うことができます。複雑で、私は知っている。 [こちら](https://shiny.rstudio.com/articles/dynamic-ui.html) – RobertMc

+0

@RobertMcを参照してください。さて、私はそれをしました。私は今、チャートの実際の値ではなく、「質問」チャートの見出しとして答えの選択肢を与えるという問題があります。私が思うに、「質問[input $ numberchoice、2:6]」は、読み込まれているcsv内の数字である実際の回答の選択肢の代わりに見出し(AからEまでの名前)を返しています。 – Zack

+0

まあ、問題を再現するサンプルデータを使用して質問を更新できますか? – RobertMc

答えて

1

observeEventeventReactiveを交換してみてください。次のコードは私のために働く。

library(shiny) 

ui <- fluidPage(
    selectInput("numberchoice", label = "Choose an image", choices = 1:6, selected = 1), 
    radioButtons("answerchoice", "Answers", choices = 1:6) 

) 

server <- function(input, output, session) { 
    observeEvent(input$numberchoice,{ 
    updateRadioButtons(session, "answerchoice", 
     choices = letters[1:input$numberchoice])}) 
} 

shinyApp(ui = ui, server = server) 

eventReactiveupdateRadioButtonsは問題ではなかったので、トリガしていなかったように思えます。

関連する問題