闪亮的仪表板下拉菜单
Shiny Dashboards Dropdown
所以我在 Shiny 中有一个仪表板。它很简单 table 看起来像 [在这个 link][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));",
"}")))
})
所以我在 Shiny 中有一个仪表板。它很简单 table 看起来像 [在这个 link][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));",
"}")))
})