2016-05-07 7 views
0

ラジオボタン(input $ relStat)を使用して、各オプションがtextOutputの異なる計算を実行するようにします。入力はbasicIncomeのスライダーから、childNumの数値から得られます。ラジオボタンを使用して計算を変更する

ui.R

sliderInput(inputId = "basicIncome", 
       label = "Choose a monthly basic income", 
       value = 600, min = 0, max = 1200, step = 50 
), 

textOutput("annualBasicIncome"), 
) 

server.R

annualBasicIncome <- eventReactive(input$updateButton, { 
    if ("1" %in% input$relStat) 
    renderText({(input$basicIncome*12)+((input$basicIncome*12)*input$childNum)}) 

    if ("2" %in% input$relStat) 
    renderText({(2*(input$basicIncome*12))+((input$basicIncome*12)*input$childNum)}) 
}) 

output$annualBasicIncome <- renderText({ 
    annualBasicIncome() 
}) 

私は値にラジオボタンを与えることを試みました。しかしバイナリ。

最初のif("1")を削除した場合、1つのラジオボタンオプションでは何も表示されず、もう1つはエラーargument 1 (type 'closure') cannot be handled by 'cat'が表示されます。

答えて

0

試してみてください。

switch(as.numeric(input$relStat), 
    return((input$basicIncome*12)+((input$basicIncome*12)*input$childNum)), 
    return((2*(input$basicIncome*12))+((input$basicIncome*12)*input$childNum)) 
) 

あなたが望む結果を得る必要があります。

+0

ありがとうございます!私はまだうんざりしている。この塊がどこに行くのか教えていただけますか?私は、例2 [ここ](http://shiny.rstudio.com/articles/basics.html)と同様の方法でrelStat $ Inputを無駄に保存しようとしました。 ' – gizzard

+0

@ gizzard、if文の代わりにスイッチを試してください(編集時)。 'annualBasicIncome()'が表示したい値を取得するため、 'return'を使用していることが分かります。そして、あなたが書いた関数はそれを出力しなければなりませんが、動作しない場合は 'renderText'の代わりに' textOutput'と 'renderPrint'の代わりに' verbatimTextOutput'を使ってみてください。乾杯。 – arodriguezca

+0

編集しました、ありがとうございます! – gizzard

関連する問題