闪亮的仪表板下拉列表(Shiny Dashboards Dropdown)
所以我在Shiny中有一个仪表板。 这只是一个简单的表,看起来像[在这个链接中找到的图像] [1](道歉,我不能给你一些更可重复的东西。不知道我会怎么做。)
So I have a dashboard in Shiny. It's just simple table that looks like [the image found in this link][1] (apologies that I can't give you something more reproducible. Not sure how I would do that.)
最满意答案
一个有效的应用程序:
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));", "}"))) })A working shiny app:
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));", "}"))) })更多推荐
发布评论