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.
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.
Does anyone know how to do this in Shiny?
Thanks for any help!
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)
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)