2016-07-27 4 views
1

私はrシャイニーで新しく、ラジオボタンの選択値を変数として取得し、それを別のものと連結しようとしています。私はそれが "ncount" のではなく、変数に格納された値を出力ncountを印刷するときr shiny - 変数としてラジオボタンの値を取得

ui.R

library(shiny) 
shinyUI(fluidPage(
    titlePanel("This is test app"), 

    sidebarLayout(
    sidebarPanel(
     radioButtons("rd", 
        label="Select window size:", 
        choices=list("100","200","500","1000"), 
        selected="100") 
    ), 
    mainPanel(
     //Something 
    ) 
) 
)) 

今server.R

library(shiny) 

shinyServer(function(input, output) { 


    ncount <- reactive({input$rd}) 
    print(ncount) 
    my_var <- paste(ncount,"100",sep="_") 

}) 

:ここに私のコードです。私がここで紛失しているものはありますか?

おかげ

答えて

6

UI

library(shiny) 
shinyUI(fluidPage(
    titlePanel("This is test app"), 

    sidebarLayout(
    sidebarPanel(
     radioButtons("rd", 
        label = "Select window size:", 
        choices = list("100" = 100,"200" = 200,"500" = 500,"1000" = 1000), 
        selected = 100) 
    ), 
    mainPanel(
     verbatimTextOutput("ncount_2") 
    ) 
) 
)) 

サーバー

library(shiny) 

shinyServer(function(input, output) { 


# The current application doesnt need reactive 

    output$ncount_2 <- renderPrint({ 
    ncount <- input$rd 
    paste(ncount,"100",sep="_") 
    }) 

    # However, if you need reactive for your actual data, comment the above part 
    # and use this instead 


    # ncount <- reactive({input$rd}) 
    # 
    # output$ncount_2 <- renderPrint({ 
    # paste(ncount(),"100",sep="_") 
    # }) 



}) 
+0

私はあなたの答えが、詳細な説明に感謝して投票十分な評判を持っていません。 – dagg3r

関連する問題