2016-07-27 13 views
1

Ich bin neu mit r glänzend und ich versuche, ausgewählten Wert eines Radio-Button als Variable und dann verketten es mit etwas anderem. Hier ist mein Code:r glänzend - Erhalte Radio-Button-Wert als Variable

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

}) 

Wenn ich jetzt ncount ausdrucken druckt "nCount", anstatt den Wert in der Variablen gespeichert. Gibt es irgendetwas, was ich hier vermisse?

Dank

Antwort

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

Server

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

ich oben nicht genug Ruf haben, um Ihre Antwort, aber Dank für ausführliche Erklärung zu stimmen. – dagg3r