2017-10-03 3 views
2

R Shiny에서 나는 버튼의 값이 위에 표시되고 여러 질문의 라디오 버튼이 버튼 값에 정렬되는 여러 그룹화 된 라디오 버튼의 구현으로 다음 스크립트를 작성했습니다.r에 라디오 버튼 정렬 Shiny

library(shiny) 

ui <- fluidPage(
    titlePanel(title=HTML("&nbsp;"), windowTitle="Questionaire"), 

    cellWidths = c("100%"), 
    cellArgs = list(style = "padding: 6px"), 

    wellPanel(
    splitLayout(cellWidths = c("25%","10%","10%","10%","10%","10%"),"", 
       p("strongly agree"),p("agree"),p("neutral"),p("disagree"),p("strongly disagree")), 

    splitLayout(cellWidths = c("25%","10%","10%","10%","10%","10%"),p(strong("The website has a user friendly interface:")), 
       radioButtons("use1", "", "", selected=0, inline = T), 
       radioButtons("use2", "", "", selected=0, inline = T), 
       radioButtons("use3", "", "", selected=0, inline = T), 
       radioButtons("use4", "", "", selected=0, inline = T), 
       radioButtons("use5", "", "", selected=0, inline = T)), 

    splitLayout(cellWidths = c("25%","10%","10%","10%","10%","10%"),p(strong("The website is easy to navigate:")), 
       radioButtons("nav1", "", "", selected=0, inline = T), 
       radioButtons("nav2", "", "", selected=0, inline = T), 
       radioButtons("nav3", "", "", selected=0, inline = T), 
       radioButtons("nav4", "", "", selected=0, inline = T), 
       radioButtons("nav5", "", "", selected=0, inline = T)) 
) 
) 

server <- function(input, output, session) 
{ 
} 

shinyApp(ui = ui, server = server) 

이 구현에서는 질문 당 여러 옵션을 확인할 수 있습니다. 사용자가 질문에 대한 옵션을 선택한 후에는 사용자가 이후에 같은 질문에 대해 다른 옵션을 선택하자마자이 선택이 선택 취소됩니다.

답변

2

조금 도움이 되었기를 바랍니다. 아직 조정할 필요가 있습니다. 그리드를 얻는 가장 좋은 방법은 각 '질문'에 대해 하나의 라디오 버튼 옵션을 갖는 것입니다. 이것을 그리드로 설정하려면 $ style 태그의 CSS 설정으로 재생해야 할 수도 있습니다. 예 :

ui <- fluidPage(

tags$style(".checkbox-inline, .radio-inline { 
    text-align: center; 
    margin-left: 0px; 
    margin-right: 0px; 
    padding: 0px; 
width: 20%;} "), 

titlePanel(title=HTML("&nbsp;"), windowTitle="Questionaire"), 



cellWidths = c("100%"), 
cellArgs = list(style = "padding: 6px"), 

wellPanel(
    # Introduced div to centre align the headers 
    splitLayout(cellWidths = c("25%","10%","10%","10%","10%","10%"),"", 
          div(style="text-align:center", HTML("strongly agree")), 
          div(style="text-align:center", HTML("agree")), 
          div(style="text-align:center", HTML("neutral")), 
          div(style="text-align:center", HTML("disagree")), 
          div(style="text-align:center", HTML("strongly disagree"))), 

    splitLayout(cellWidths = c("25%","50%"), 
          p(strong("The website has a user friendly interface:")), 
          radioButtons("use1", "", choiceValues=1:5, choiceNames=rep("",5), selected=0, inline = T) 
    ), 

    splitLayout(cellWidths = c("25%","50%"), 
          p(strong("The website is easy to navigate:")), 
          radioButtons("nav1", "", choiceValues=1:5, choiceNames=rep("",5), selected=0, inline = T) 
    )) 
) 
+0

감사합니다. 그러나 높이/너비 비율이 변경되도록 창을 변경할 때 라디오 버튼이 더 이상 위쪽에 표시된 5 개의 레이블에 올바르게 정렬되지 않습니다. 이것은 사용자가 상이한 높이/폭 비율을 갖는 스크린을 사용할 수 있기 때문에 문제가된다. –

+0

무슨 뜻인지 알 겠어, 라디오 버튼이 태그 $ 스타일 (5 옵션의 경우 100 %/5)에서 20 %의 너비로 설정하여 화면의 크기를 조절할 수 있도록 내 대답을 편집했지만 스크롤 바가 생겼다. 어떻게 제거하는 지. 틀림없이 나는 HTML 전문가가 아닙니다 – KGee

+0

다시 한 번 감사드립니다. 'radioButtons'에 매개 변수로 'width = 90'을 추가하면 창이 너무 좁지 않으면 스크롤 막대가 사라집니다. –