Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 826
SeGa Avatar asked Aug 20 '19 12:08

SeGa


1 Answers

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

like image 57
Rushabh Patel Avatar answered Nov 06 '22 10:11

Rushabh Patel