简体   繁体   中英

How to avoid collapsing with shinyWidgets dropdown and a datatable

I want to display a spreadsheet with some information in shinyWidgets dropdown , sometimes spanning multiple pages.

If you click on the next page, the dropdown closes again.
How can I avoid this?

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  br(),br(),br(),
  p("How to go to the next page, without collapsing?"),
  uiOutput("irisdrop", inline = TRUE)
)

server <- function(input, output, session) {
  output$irisdrop <- renderUI({
    dropdown(circle = FALSE, inputId = "iris",
             label = "iris", status = "primary", 
             datatable(iris, rownames = NULL,
                       height = "100%",
                       selection = "none"
             )
    )
  })
}

shinyApp(ui, server)

You can do something like this -

library(shiny)
library(shinyWidgets)
library(DT)


ui <- fluidPage(
  dropdownButton(
    inputId = "iris",
    label = "iris",
    icon = icon("sliders"),
    status = "primary",
    circle = FALSE,
    DT::dataTableOutput("iris_tb")
  )
)


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

  output$iris_tb <- DT::renderDataTable({

    datatable(iris, rownames = NULL,
              height = "100%",
              selection = "none"
    )

  })
}

shinyApp(ui, server)

Note: You can even use dropdown() instead of dropdownButton() from shinyWidgets package.

dropdown() is similar to dropdownButton() but it don't use Bootstrap, so you can put pickerInput in it. Moreover you can add animations on the appearance / disappearance of the dropdown with animate.css .

For more detail, you can look at the page 30 of the following document -

https://cran.r-project.org/web/packages/shinyWidgets/shinyWidgets.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM