2016-03-18 24 views
3

Sayısal bir giriş için kullanıcıyı soran ve ardından bu girişe dayanarak 4 tane daha giriş alanı oluşturan bir dinamik girişe sahip R parlak bir uygulama oluşturmak istiyorum. İşte aklımda olan şey.R Parlak Dinamik Giriş

library(shiny) 

# Define UI for random distribution application 
shinyUI(fluidPage(

    # Application title 
    titlePanel("Calcs"), 

    # Sidebar with controls to select the random distribution type 
    # and number of observations to generate. Note the use of the 
    # br() element to introduce extra vertical spacing 
    sidebarLayout(
    sidebarPanel(
    numericInput("dorr", "How many inputs do you want",4), 
    i = i+1 
    while(input$dorr<i){ 
     numericInput("S", "Number of simulations to run:", 10) 
     i=i+1 
    } 
    numericInput("S", "Number of simulations to run:", 10), 
    actionButton(inputId = "submit_loc",label = "Run the Simulation") 
    ), 


    mainPanel(

) 
))) 

Yukarıdaki kodun çalışmadığını biliyorum, ancak bu benim mantığım. Shiny'ın şartlı ifadeleri olduğunu biliyorum ama önceden belirlenmiş sayıda ek alan oluşturmamı sağlayan bir tane bulamıyorum. Bu mümkün mü?

+0

altında bir çalışma örneğe bakın. Bazı örnekler için bu sayfaya bakın http://shiny.rstudio.com/articles/dynamic-ui.html –

+0

@warmoverflow Bildiğim kadarıyla, önceden tanımlanmış bir dinamik oluşturmak için bunu nasıl kullanacağımı anlamıyorum. giriş sayısı. – RustyStatistician

cevap

3

Sunucu kodunda `renderUI` kullanmak gerekir

library(shiny) 

ui <- shinyUI(fluidPage(
    titlePanel("Old Faithful Geyser Data"), 

    sidebarLayout(
    sidebarPanel(
     numericInput("numInputs", "How many inputs do you want", 4), 
     # place to hold dynamic inputs 
     uiOutput("inputGroup") 
    ), 
    # this is just a demo to show the input values 
    mainPanel(textOutput("inputValues")) 
) 
)) 

# Define server logic required to draw a histogram 
server <- shinyServer(function(input, output) { 
    # observe changes in "numInputs", and create corresponding number of inputs 
    observeEvent(input$numInputs, { 
    output$inputGroup = renderUI({ 
     input_list <- lapply(1:input$numInputs, function(i) { 
     # for each dynamically generated input, give a different name 
     inputName <- paste("input", i, sep = "") 
     numericInput(inputName, inputName, 1) 
     }) 
     do.call(tagList, input_list) 
    }) 
    }) 

    # this is just a demo to display all the input values 
    output$inputValues <- renderText({ 
    paste(lapply(1:input$numInputs, function(i) { 
     inputName <- paste("input", i, sep = "") 
     input[[inputName]] 
    })) 
    }) 

}) 

# Run the application 
shinyApp(ui = ui, server = server) 
+0

Cevabınıza dayalı yeni bir soru açtım, belki bir göz atabilirsiniz: http://stackoverflow.com/questions/36141451/ammending-dynamic-input-code-in-r-shiny – RustyStatistician