R Shiny 包装 UI 元素

标签 r shiny

有什么办法可以包裹UI元素吗?我有一个 checkboxGroupInput,我想包装这些元素,以便它们适合整个 wellPanel

编辑:下面添加了可重现的示例。

在 wellPanel 中列出复选框的位置,我想要一种将其包裹到 wallPanel 宽度的方法,以便节省空间并创建更好的布局。有什么建议么?

全局.R

library(shiny)
library(shinyIncubator)
data_in <- c(1:50)

ui.R

library(shiny)
library(shinyIncubator)

shinyUI(fluidPage(
  fluidRow(
    headerPanel('Test Page')
  ),
  fluidRow(
    plotOutput('plot')
  ),
  fluidRow(
    wellPanel(uiOutput("checkbGroups"))
  )
))

服务器.R

shinyServer(function(input, output) {
  values <- reactiveValues()

  datasetInput <- reactive({
    values$data <- input$foo
  })

  plotInput <- reactive({
    datasetInput()
    plot(x=values$data, y=values$data, col=values$data)
  })

  output$checkbGroups <- renderUI({
    checkboxGroupInput(inputId = 'foo', label = 'Numbers To use', 
                       choices = data_in, 
                       selected = data_in)
  })

  output$plot <- renderPlot({
    plotInput()
  })
})

最佳答案

您可以在复选框上添加一些样式

library(shiny)
library(shinyIncubator)
data_in <- c(1:50)

runApp(
  list(ui = fluidPage(
    fluidRow(headerPanel('Test Page')),
    fluidRow(plotOutput('plot')),
    fluidRow(wellPanel(uiOutput("checkbGroups")))
  ),
  server = function(input, output) {
    values <- reactiveValues() 
    datasetInput <- reactive({
      values$data <- input$foo
    })
    plotInput <- reactive({
      datasetInput()
      plot(x=values$data, y=values$data, col=values$data)
    })
    output$checkbGroups <- renderUI({
      test <- checkboxGroupInput(inputId = 'foo', label = 'Numbers To use', 
                         choices = data_in, 
                         selected = data_in)
      gsub("class=\"checkbox\"", "class=\"checkbox\" style=\"float:left; margin:25px;\"", test)
    })
    output$plot <- renderPlot({plotInput()})
  })
)

enter image description here

关于R Shiny 包装 UI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24205676/

相关文章:

r - ggplot2,如何在 geom_text 中跳过 NA

r - 为模拟研究运行多次重复 Rcpp 函数的最有效方法?

r - 如何测试绘图在 R 中是否具有固定的纵横比

r - Shiny :如果 radioButtions() 为空/未选中​​,actionButton() 能否返回错误?

r - 如何在shinyapp传单 map 中使用clusterOptions?

r - 在 R 中找到矩阵的相邻元素

R:删除列中的重复元素,保留第一次出现并重新定位值

r - Shiny 的应用程序下载按钮和 future_promise : Error in enc2utf8: argument is not a character vector

Shiny 的仪表板侧边栏无法展开多个选项卡

javascript - r - 如何在 shinyapp 中自动滚动到 div 的底部?