r Shiny 中对齐的单选按钮
aligned radio buttons in r Shiny
在 R Shiny 中,我编写了以下脚本作为多个分组单选按钮的实现,其中按钮的值显示在顶部,并且多个问题的单选按钮与这些按钮值对齐:
library(shiny)
ui <- fluidPage(
titlePanel(title=HTML(" "), 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)
在此实现中,可以检查每个问题的多个选项。如何更改代码以便在用户为某个问题选择一个选项后,只要用户随后为同一问题选择另一个选项,该选项就会被取消选择?
希望这对您有所帮助,它可能仍需要一些调整。我认为获得网格的最佳方法是为每个 'question' 设置一个单选按钮选项。为了将其设置为网格,您可能需要使用 tags$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(" "), 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)
))
)
在 R Shiny 中,我编写了以下脚本作为多个分组单选按钮的实现,其中按钮的值显示在顶部,并且多个问题的单选按钮与这些按钮值对齐:
library(shiny)
ui <- fluidPage(
titlePanel(title=HTML(" "), 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)
在此实现中,可以检查每个问题的多个选项。如何更改代码以便在用户为某个问题选择一个选项后,只要用户随后为同一问题选择另一个选项,该选项就会被取消选择?
希望这对您有所帮助,它可能仍需要一些调整。我认为获得网格的最佳方法是为每个 'question' 设置一个单选按钮选项。为了将其设置为网格,您可能需要使用 tags$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(" "), 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)
))
)