2016-07-27 67 views
1

我是新的r闪亮,我试图获取选定的单选按钮值作为变量,然后连接它与其他东西。这里是我的代码:r闪亮 - 获取单选按钮值作为变量

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="_") 

}) 

现在,当我打印ncount它打印出 “NCOUNT”,而不是存储在变量中的值。有什么,我在这里失踪。

感谢

回答

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