【问题标题】:How can you add an explanation to shiny datatable column? [duplicate]如何为闪亮的数据表列添加解释? [复制]
【发布时间】:2015-12-20 17:39:40
【问题描述】:

我在数据表的帮助下编写了一个闪亮的应用程序,我想制作一个小盒子来解释每一列的含义。理想情况下,我希望它们在您将光标移到列名称上时出现。

这是一个应用程序:

ui.R

library(shiny)

data(iris)

shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        column(12,
               wellPanel(
                 radioButtons("species", label="Species:", 
                              choices=levels(iris$Species),
                              selected=levels(iris$Species)[1]

                 )
               )
        )
      )
    ),
    mainPanel(
      fluidRow(column(12,
                      dataTableOutput("table1")

      )
      )
    )
  )
)
)

server.R

library(shiny)
library(dplyr)
library(tidyr)

data(iris)  


shinyServer(function(input, output) {

  iris1 <- reactive({
    iris %>% 
      filter(Species %in% input$species)
  })

  output$table1 <- renderDataTable({
    iris1()
  })
})

当您将 courser 移到 Species 列名称上时,我希望有这样的东西:

有可能吗?请帮忙。

【问题讨论】:

  • 是的,这是可能的,但是您没有显示任何数据表初始化代码,因此没有太多可使用的...
  • renderDataTable 不会在应用程序中制作数据表吗?看起来像一个:)
  • 如果没有,你能写一个用于datables的awser吗?
  • 我还没有尝试过,但看起来你可以使用DT 包轻松做到这一点:stackoverflow.com/questions/31124122/…
  • 谢谢,这对我有用:stackoverflow.com/questions/31124122/…

标签: r datatables shiny


【解决方案1】:

感谢this 我设法做出了我想要的输出:

ui.R - 没有任何变化

server.R

library(shiny)
library(dplyr)
library(tidyr)

data(iris)  

shinyServer(function(input, output) {

  iris1 <- reactive({
    iris %>% 
      filter(Species %in% input$species)
  })

  output$table1 <- renderDataTable(iris1(), callback = htmlwidgets::JS("
        var tips = ['Row Names', 'The Sepal Length', 'The Sepal Width',
                    'The Petal Length', 'The Petal Width'],
            header = table.columns().header();
        for (var i = 0; i < tips.length; i++) {
          $(header[i]).attr('title', tips[i]);
        }
"))
})

它在 JavaScript 变量 tips 中定义解释框。

【讨论】:

    猜你喜欢
    • 2019-10-23
    • 2022-08-03
    • 2015-03-12
    • 2018-07-06
    • 2021-12-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    相关资源
    最近更新 更多