dreamRs / shinytreeview

Hierarchical tree input for Shiny apps
GNU General Public License v3.0
41 stars 8 forks source link

Scrollable input #6

Closed LELULAS closed 1 year ago

LELULAS commented 2 years ago

My list is very long, especially when certain categories are expanded. Is there some way to make it scrollable?

pvictor commented 2 years ago

Hello,

You can make it scrollable by adding some CSS styles directly to the input itself or by placing the widget inside a container like a div. Here's an example where it set maximal height for the input by adding styles with package {htmltools} :

library(shiny)
library(shinytreeview)

data("world.cities", package = "maps")
choices <- maps::world.cities |> 
  subset(pop > 1e5) |> 
  make_tree(c("country.etc", "name"))

ui <- fluidPage(
  tags$h3("treeviewInput cities example"),
  treeviewInput(
    inputId = "tree",
    label = "Choose a city:",
    choices = choices,
    multiple = FALSE
  ) |> htmltools::tagAppendAttributes(style = "max-height: 600px; overflow: auto;"),
  verbatimTextOutput(outputId = "result")
)

server <- function(input, output, session) {
  output$result <- renderPrint({
    input$tree
  })
}

if (interactive())
  shinyApp(ui, server)
LELULAS commented 2 years ago

Thank you!!