如何在 RShiny 中动态更改列的宽度? [英] How to dynamically change the width of columns in RShiny?

查看:37
本文介绍了如何在 RShiny 中动态更改列的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以(如果可以,如何)在 RShiny 中动态更改列的宽度?

I was wondering if it is possible (and if so, how) to dynamically change the width of columns in RShiny?

下面是一个简单的可重复示例,说明我如何认为这可以工作(但不会,如果您取消对服务器部分的注释,应用程序会崩溃).基本上我想做的是有一个滑块,可以调整列的宽度.

A simple reproducible example of how I figured this could work (but doesn't, the app crashes if you un-comment the server section) is below. Essentially what I would like to do is have a slider, that resizes the width of the columns.

也许我真正想做的更好、更优雅的例子是这里(link).我想要两个相邻的面板,当您调整其中一个的宽度(即向左或向右拖动面板的边框)时,它旁边的面板会自动调整大小以适应空间.

Perhaps a better, more elegant example of what I'd actually like to do is here (link). I'd like two panels next to each other and, as you resize the width of one (i.e. drag the border of the panel left or right), the panel next to it automatically resizes to fit the space.

有谁知道如何在 Shiny 中做到这一点?

Does anyone know how to do this in Shiny?

感谢您的帮助!

library(shiny)

length_1 = 2
length_2 = 10

ui <- fluidPage(
 fluidRow(
   column(width = length_1,"Text"),
   column(width = length_2,"More text")
 ),
 fluidRow(
   column(
   width = 12, sliderInput("length","slide",min = 0,max = 12,value = 2)
 ))
)

server <- function(input, output, session) {
  #length_1 = input$length
  #length_2 = 12-input$length

}

shinyApp(ui, server)

推荐答案

您可以使用 renderUI 来做到这一点

You can use renderUI to do that

library(shiny)
ui <- fluidPage(
    fluidRow(
        column(
            width = 12, sliderInput("length","slide",min = 1, max = 11,value = 2)
        )),
    fluidRow(
        uiOutput("cols")
    )
)

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

    output$cols <- renderUI({
        tagList(
            column(width = input$length,"Text"),
            column(width = 12-input$length,"More text")
        )
    })
}

shinyApp(ui, server)

这篇关于如何在 RShiny 中动态更改列的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆