【问题标题】:How to avoid collapsing with shinyWidgets dropdown and a datatable如何避免使用shinyWidgets 下拉列表和数据表崩溃
【发布时间】:2019-12-25 15:38:39
【问题描述】:

我想在shinyWidgets下拉列表中显示一个包含一些信息的电子表格,有时跨越多个页面。

如果您点击下一页,下拉菜单会再次关闭。
如何避免这种情况?

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)

【问题讨论】:

  • 可能不是您要找的,但来自shinydashboarddropdownButton 不会发生这种情况。

标签: r shiny shinywidgets


【解决方案1】:

你可以这样做 -

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)

注意:您甚至可以使用 dropdown() 代替 shinyWidgets 包中的 dropdownButton()

dropdown()dropdownButton() 类似,但它不使用Bootstrap,因此您可以将pickerInput 放入其中。此外,您可以使用animate.css 在下拉菜单的外观/消失上添加动画。

更详细的可以看下面文档的第30页-

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

【讨论】:

  • 谢谢,如果在服务器函数中创建dropdown,这也有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多