伟大的R社区,
我只是想知道是否有可能通过按下操作按钮以模式显示DT::dataTableOutput。例如,数据表输出如下所示。

r - 在 Shiny 的应用程序中以模式显示dataTableOutput-LMLPHP

这是一些开始的代码:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(

  dashboardHeader(),
  ## Sidebar content
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  ),

  ## Body content
  dashboardBody(
    tabItems(
      # First tab content
      tabItem(tabName = "dashboard",
              actionButton("showTable", "Show Table", icon = icon("table"))
              ##fluidRow( DT::dataTableOutput('tbl') )
              ## SOME CODE TO SHOW DATA TABLE IN MODAL
      )
    )
  )
)

server <- function(input, output) {
  output$tbl = DT::renderDataTable(
    iris, options = list(lengthChange = FALSE)
  )
}

shinyApp(ui, server)

最佳答案

感谢Ryan的快速建议。钉上钉子。这是我的工作示例:

## app.R ##
library(shiny)
library(shinyBS)
library(shinydashboard)

ui <- dashboardPage(

  dashboardHeader(),
  ## Sidebar content
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  ),

  ## Body content
  dashboardBody(
    tabItems(
      # First tab content
      tabItem(tabName = "dashboard",
              actionButton("showTable", "Show Table", icon = icon("table")),
              bsModal("modalExample", "Data Table", "showTable", size = "large",
                      dataTableOutput("tbl"))
      )
    )
  )
)

server <- function(input, output) {
  output$tbl = renderDataTable( iris, options = list(lengthChange = FALSE))
}

shinyApp(ui, server)

关于r - 在 Shiny 的应用程序中以模式显示dataTableOutput,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43748316/

10-12 19:23