数据表无法在Shinydashboard中渲染。它只是为盒子呈现一条薄薄的白色条带。仅在RStudio中运行数据表函数会在RStudio查看器中呈现数据表。那么在闪亮的应用程序中呈现DT数据表的正确方法是什么?
## app.R ##
library(shiny)
library(shinydashboard)
library(htmlwidgets)
library(DT)
library(xtable)
source('../ts01/db.R')
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(tableOutput("table1"))
)
)
)
server <- function(input, output) {
output$table1 <- DT::renderDataTable({
datatable(amount_data)
})
}
shinyApp(ui, server)
答案 0 :(得分:6)
You should try the following:
1) tableOutput
rm(list = ls())
library(shiny)
library(shinydashboard)
my_data <- head(mtcars)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(tableOutput("table1"))
)
)
)
server <- function(input, output) {
output$table1 <- renderTable({
my_data
})
}
shinyApp(ui, server)
2) dataTableOutput
rm(list = ls())
library(shiny)
library(DT)
library(shinydashboard)
my_data <- head(mtcars)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(DT::dataTableOutput("table1"))
)
)
)
server <- function(input, output) {
output$table1 <- DT::renderDataTable({
datatable(my_data)
})
}
shinyApp(ui, server)
答案 1 :(得分:2)
要确保使用正确的包来渲染数据表,请改用ui:
DT::dataTableOutput('table1')