2014-06-12 4 views
1

제목은 모두 정말로 말하며, 여러 UI 요소를 만드는 방법을 생각하려고합니다.R 반짝이 - n 개의 UI 요소 생성하기

셀렉터에 n 개의 요소가있는 경우 (데이터 세트) - 이러한 각 데이터 세트의 이름이 다른 것과 길이가 다른 경우가 있습니다. 이 열 이름을 그룹 입력으로 사용하고 싶습니다.

얼마나 많은 데이터 세트가 있을지 알고 있다면 정적으로 할 수 있다고 생각합니다. 예를 들어 checkboxgroupinput을 반복 생성 할 수있는 방법이 있습니까?

ui.r

library(shiny) 
shinyUI(pageWithSidebar(

    # Application title 
    headerPanel("Example"), 


    sidebarPanel(
    checkboxGroupInput("one", "One:",data_in[[1]]), 
    checkboxGroupInput("two", "Two:",data_in[[2]]), 

), 

    mainPanel(

) 
)) 

답변

3

예를 사용할 수 있습니다 renderUI

data_in <- c("Cylinders" = "cyl", 
      "Transmission" = "am", 
      "Gears" = "gear") 
library(shiny) 
runApp(
    list(ui = pageWithSidebar(
    headerPanel("Example"), 
    sidebarPanel(
     uiOutput("checkbGroups") 
    ), 
    mainPanel(
    ) 
) 
    , 
    server = function(input, output, session){ 
    output$checkbGroups <- renderUI({ 
     lapply(1:10, function(x){ 
     do.call(checkboxGroupInput, list(inputId = x, label = x, choices = data_in)) 
     } 
    ) 
    } 
    ) 
    } 
) 
) 

enter image description here

관련 문제