首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >uiOutput中的列(闪亮)

uiOutput中的列(闪亮)
EN

Stack Overflow用户
提问于 2016-08-22 15:28:07
回答 1查看 2.4K关注 0票数 0

在using中,我使用renderUItagList在服务器元素中动态创建UI,然后使用uiOutput显示它。它可以工作,但我想将uiOutput的内容分解为列。我该怎么做?

下面是来自闪亮图库的动态UI示例(略为缩写)。注意output$ui是如何包含以一列形式显示的tagList的,但我希望它显示为两列。

请注意,我不能在column中调用renderUI

代码语言:javascript
复制
library(shiny)

server <- shinyServer(function(input, output) {
  output$ui <- renderUI({
    if (is.null(input$input_type)) {return()}
    tagList(list(div("Want this to be left column"),
         switch(input$input_type,
           "slider" = sliderInput("dynamic", "Want this to be right column",
                                  min = 1, max = 20, value = 10),
           "text" = textInput("dynamic", "Want this to be right column",
                              value = "starting value"),
           "numeric" =  numericInput("dynamic", "Want this to be right column",
                                     value = 12),
           "checkbox" = checkboxInput("dynamic", "Want this to be right column",
                                      value = TRUE))))
  })
  output$input_type_text <- renderText({input$input_type})
  output$dynamic_value <- renderPrint({str(input$dynamic)})
})

ui <- shinyUI(fluidPage(
  titlePanel("Dynamically generated user interface components"),
  wellPanel(selectInput("input_type", "Input type",
                        c("slider", "text", "numeric", "checkbox")
  )),
  wellPanel(uiOutput("ui")),
  wellPanel(
    tags$p("Input type:"),
    verbatimTextOutput("input_type_text"),
    tags$p("Dynamic input value:"),
    verbatimTextOutput("dynamic_value")
  )
))

shinyApp(ui = ui, server = server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-22 15:57:48

而不是将div和选定的小部件包装到list中,然后再封装到tagList中(您不需要两者都需要--其中一个就足够了)

代码语言:javascript
复制
tagList(list(div("Want this to be left column"), switch(...) ...)

创建fluidRow并添加两列--一列带有div,另一列带有switch

代码语言:javascript
复制
fluidRow(column(6, div("Want this to be left column")),
         column(6, switch(input$input_type,
                        "slider" = sliderInput("dynamic", "Want this to be right column",
                                               min = 1, max = 20, value = 10),
                        "text" = textInput("dynamic", "Want this to be right column",
                                           value = "starting value"),
                        "numeric" =  numericInput("dynamic", "Want this to be right column",
                                                  value = 12),
                        "checkbox" = checkboxInput("dynamic", "Want this to be right column",
                                                   value = TRUE)
                  )
          )
        )

完整示例:

代码语言:javascript
复制
library(shiny)

server <- shinyServer(function(input, output) {
  output$ui <- renderUI({
    if (is.null(input$input_type)) {return()}
    fluidRow(column(6, div("Want this to be left column")),
             column(6, switch(input$input_type,
                              "slider" = sliderInput("dynamic", "Want this to be right column",
                                                     min = 1, max = 20, value = 10),
                              "text" = textInput("dynamic", "Want this to be right column",
                                                 value = "starting value"),
                              "numeric" =  numericInput("dynamic", "Want this to be right column",
                                                        value = 12),
                              "checkbox" = checkboxInput("dynamic", "Want this to be right column",
                                                         value = TRUE)
             )
             )
    )
  })
  output$input_type_text <- renderText({input$input_type})
  output$dynamic_value <- renderPrint({str(input$dynamic)})
})

ui <- shinyUI(fluidPage(
  titlePanel("Dynamically generated user interface components"),
  wellPanel(selectInput("input_type", "Input type",
                        c("slider", "text", "numeric", "checkbox")
  )),
  wellPanel(uiOutput("ui")),
  wellPanel(
    tags$p("Input type:"),
    verbatimTextOutput("input_type_text"),
    tags$p("Dynamic input value:"),
    verbatimTextOutput("dynamic_value")
  )
))

shinyApp(ui = ui, server = server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39083419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档