所以我在Shiny中有一个仪表板。它只是一个简单的表格,看起来像[在这个链接中找到的图像] [1](道歉,我不能给你一些更可重复的东西。不知道我会怎么做。)
答案 0 :(得分:1)
一个有效的应用程序:
ui.R
library(shiny)
library(DT)
library(htmltools)
fluidPage(
title = 'DataTables Information',
h1('A client-side table'),
fluidRow(
column(12,
selectInput("speciesSelector",
"Select species",
choices = c("All", levels(iris$Species)),
selected = "All"),
DT::dataTableOutput('iris')
)
)
)
server.R
library(shiny)
library(DT)
library(htmltools)
sketch <- htmltools::withTags(table(
class = "display",
style = "bootstrap",
tableHeader(c("ID", colnames(iris))),
tableFooter(c("ID", colnames(iris)))
))
shinyServer(function(input, output, session) {
data <- reactive({
data <- iris
if (input$speciesSelector != "All") {
data <- data[data$Species == input$speciesSelector,]
}
data
})
# render the table (with row names)
output$iris = DT::renderDataTable(data(),
container = sketch,
server = FALSE,
caption = "Column sum example",
filter = "top", options = list(footerCallback = JS(
"function( tfoot, data, start, end, display ) {",
"var api = this.api(), data;",
"total = api.column( 4, { page: 'current'} ).data().reduce( function ( a, b ) {return a + b;} )",
"total1 = api.column( 4, { search:'applied'} ).data().reduce( function ( a, b ) {return a + b;} )",
"$( api.column( 4 ).footer() ).html(total.toFixed(2) + ' / ' + total1.toFixed(2));",
"}")))
})