r闪亮:突出显示一些细胞 [英] r shiny: highlight some cells

查看:100
本文介绍了r闪亮:突出显示一些细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

闪亮的是,我使用plotOutput来输出表格,并且我想根据一些标准来突出显示它的一些单元格。
有没有什么功能可以实现这个功能?

预先感谢您!

======================



除了突出显示外,我还想添加单选按钮在表格的左边,所以我可以知道用户选择了哪些行。现在我使用renderDataTable来做到这一点,但它似乎没有突出显示功能。
是否可能?

解决方案

你好,一个没有 ggplot2 但包含 ReporteRs ,请参阅下面的应用程序,例如,主函数是 FlexTable



编辑:是的,您可以将闪亮的小部件放入HTML表格中,这里是一个 checkboxInput 用于选择行:

  library(ReporteRs)
library(shiny)
mtcars = mtcars [1: 6,]
runApp(list(
ui = pageWithSidebar(
headerPanel = headerPanel(FlexTable),
sidebarPanel = sidebarPanel(
selectInput(inputId =colCol ,label =Col to color,choices = c(None,colnames(mtcars)),selected =None),
selectizeInput(inputId =rowCol,label = ,options = rownames(mtcars),multiple = TRUE,
options = list(placeholder ='None',onInitialize = I('function(){this.setValue();}')))
),
mainPanel = mainPanel(
uiOutput(outputId =tableau),
br(),
verbatimTextOutput(outputId =row_select),
uiOutput outputId =car_selected)

),

server =函数(输入,输出,会话){

输出$ tableau< - renderUI({

#在这里我们添加复选框到表中:它创建了6个新的输入小部件
mtcars $ choice = unlist(lapply(1:nrow(mtcars),
FUN = function(x){paste(capture.output(checkboxInput(inputId = paste0(row,x),
label = paste(Row,x),
value = TRUE)) ,collapse =)}))

tabl = FlexTable(mtcars,
#调整页眉和单元格
header.cell.props = cellProperties(background.color =#003366,padding = 5),
body.cell.props = cellProperties(padding = 5),
header.text.props = textBold(color =white),
add.rownames = TRUE)

tabl = setZebraStyle(tabl,odd =#DDDDDD,even =#FFFFFF)

#设置列的颜色
if(input $ colCol!=None){
tabl = setColumnsColors(tabl,j = which(names(mtcars)%in%input $ colCol),colors =orange)
}

#设置一行的颜色
if(!is.null(input $ rowCol)){
tabl = setRowsColors(tabl,i = which(rownames(mtcars)%)在%input $ rowCol),colors =#3ADF00)
}

return(HTML(as.html(tabl)))

})

output $ row_select< - renderPrint({
#您可以使用像其他人一样创建到表中的输入
c(row1= input $ row1,row2= input $ row2,row3= input $ row3,row4= input $ row4,row5= input $ row5,row6= input $ row6)
})

outp ut $ car_selected < - renderUI({
#如果您有超过6行,可能会很方便
selected = eval(parse(text = paste(c(,paste(paste0(input (你已经选择了以下汽车:,粘贴(rownames(mtcars)[选择],行),1:6),崩溃=,),))))
HTML )












像这样渲染(带复选框):


In shiny, I use plotOutput to output a table, and I want to highlight some cells of it according to some criteria. Is there any functions in shiny that could achieve this?

Thank you in advance!

======================

Besides to highlighting, I'd also like to add radio buttons on the left of the table, so I could know which lines user chose. Now I'm using renderDataTable to do this, however it doesn't seem to have the highlighting function. Could it be possible?

解决方案

Hello a solution without ggplot2 but with package ReporteRs, see the app below for example, the main function is FlexTable :

EDIT : yes, you can put shiny widgets into the HTML table, here an example with checkboxInput for selecting rows :

library(ReporteRs)
library(shiny)
mtcars = mtcars[1:6, ]
runApp(list(
  ui = pageWithSidebar(
    headerPanel = headerPanel("FlexTable"),
    sidebarPanel = sidebarPanel(
      selectInput(inputId = "colCol", label = "Col to color", choices = c("None",     colnames(mtcars)), selected = "None"),
      selectizeInput(inputId = "rowCol", label = "Row to color", choices = rownames(mtcars), multiple = TRUE,
                     options = list(placeholder = 'None', onInitialize = I('function() { this.setValue(""); }')))
    ),
    mainPanel = mainPanel(
      uiOutput(outputId = "tableau"),
      br(),
      verbatimTextOutput(outputId = "row_select"),
      uiOutput(outputId = "car_selected")
)
  ),

  server = function(input, output, session) {

    output$tableau <- renderUI({ 

  # here we add check box into the table: it create 6 new input widgets
  mtcars$choice = unlist(lapply(1:nrow(mtcars),
                                FUN = function(x) { paste(capture.output(checkboxInput(inputId = paste0("row", x),
                                                                                       label = paste("Row", x),
                                                                                       value = TRUE)), collapse = " ") }))

  tabl = FlexTable( mtcars,
                    # tune the header and the cells
                    header.cell.props = cellProperties( background.color = "#003366", padding = 5 ),
                    body.cell.props = cellProperties( padding = 5 ),
                    header.text.props = textBold( color = "white" ),
                    add.rownames = TRUE )

  tabl = setZebraStyle( tabl, odd = "#DDDDDD", even = "#FFFFFF" )

  # set a column's color
  if (input$colCol != "None") {
    tabl = setColumnsColors( tabl, j=which(names(mtcars) %in% input$colCol ), colors = "orange" )
  }

  # set a row's color
  if (!is.null(input$rowCol)) {
    tabl = setRowsColors( tabl, i=which(rownames(mtcars) %in% input$rowCol ), colors = "#3ADF00" )
  }

  return(HTML(as.html(tabl)))

})

output$row_select <- renderPrint({
  # you can use the input created into the table like others
  c("row1" = input$row1, "row2" = input$row2, "row3" = input$row3, "row4" = input$row4, "row5" = input$row5, "row6" = input$row6)
})

output$car_selected <- renderUI({
  # if you have more than 6 rows it could be convenient
  selected = eval(parse(text = paste("c(", paste(paste0("input$row", 1:6), collapse =", "), ")")))
  HTML(paste0("You have selected the following cars : ", paste(rownames(mtcars)[selected], collapse = ", ")))
    })
  }
))

Which render like this (with check box) :

这篇关于r闪亮:突出显示一些细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆