闪亮的仪表板下拉列表(Shiny Dashboards Dropdown)

编程入门 行业动态 更新时间:2024-10-10 11:23:28
闪亮的仪表板下拉列表(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));", "}"))) })

更多推荐

本文发布于:2023-04-29 04:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仪表板   列表   Shiny   Dashboards   Dropdown

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!