2017-01-02 21 views
3

https://github.com/rstudio/shiny-incubator/blob/master/R/tableinput.R从shinyincubator定制matrixInput函数删除+/-并显示列名

这里是链接到链接到代码为shinyIncubator包的matrixInput功能 。 我有两个问题,涉及代码的CSS/HTML部分;这是一种我不知道的语言。 下面是一个简单重复的例子:

server.R

shinyServer(function(input, output) {})

ui.R

library("shiny") 
library("shinyIncubator") 
df <- data.frame(matrix(c("0","0"), 1, 2)) 
colnames(df) <- c("first", "second") 

shinyUI(
    pageWithSidebar(
    headerPanel("Matrix input problem"), 
    sidebarPanel(
     matrixInput(inputId = 'data', label = '', data = df) 

    ) 
    , 
    mainPanel() 
) 
) 

我想更改定制matrixInput功能两件事情:

- 使行上的+/-选项消失(不可能添加行)

-Show是作为输入矩阵的列名(我看了相关的科目,但所提供的解决方案似乎并没有为我工作)

可以用经验的人在说的语言帮帮忙?

回答

0

你好,这个问题的读者。

由于我对答案的需求非常紧迫,我花了一些时间来随便尝试自己尝试,并尝试从相关主题中获得启发。 我想我有一个功能,我现在想要做的事情。 我会在这里发布代码。

基本上它和原文是一样的,但是只有一些我通过将它们作为注释而禁用,因为您会看到它们。

matrixInput2 <- function(inputId, label, data) { 
    addResourcePath(
    prefix='tableinput', 
    directoryPath=system.file('tableinput', 
           package='shinyIncubator')) 

    tagList(
    singleton(
     tags$head(
     tags$link(rel = 'stylesheet', 
        type = 'text/css', 
        href = 'tableinput/tableinput.css'), 
     tags$script(src = 'tableinput/tableinput.js') 
    ) 
    ), 

    tags$div(
     class = 'control-group tableinput-container', 
     tags$label(
     class = "control-label", 
     label 
     #THIS seems to be responsible (atleast partially, regarding the display) for the +/- buttons 
     # , 
     # tags$div(
     # class = 'tableinput-buttons', 
     # tags$button(
     #  type = 'button', class = 'btn btn-mini tableinput-settings hide', 
     #  tags$i(class = 'glyphicon glyphicon-cog icon-cog') 
     # ), 
     # HTML('<a href="#" class="tableinput-plusrow"><i class="glyphicon glyphicon-plus-sign icon-plus-sign"></i></a>'), 
     # HTML('<a href="#" class="tableinput-minusrow"><i class="glyphicon glyphicon-minus-sign icon-minus-sign"></i></a>') 
     #) 
    ), 
     tags$table(
     id = inputId, 
     class = 'tableinput data table table-bordered table-condensed', 
     tags$colgroup(
      lapply(names(data), function(name) { 
      tags$col('data-name' = name, 
        'data-field' = name, 
        'data-type' = 'numeric') 
      }) 
     ) 
     , 
     tags$thead(
      #Here I just put this line as a comment. Setting the class as 'hide' hid the column names. I don't know where the deal with the rownames is. 
      # class = 'hide', 
      tags$tr(
      lapply(names(data), function(name) { 
       tags$th(name) 
      }) 
     ) 
     ), 
     tags$tbody(
      lapply(1:nrow(data), function(i) { 
      tags$tr(
       lapply(names(data), function(name) { 
       tags$td(
        div(tabindex=0, as.character(data[i,name])) 
       ) 
       }) 
      ) 
      }) 
     ) 
    ), 
     tags$div(
     class = 'tableinput-editor modal hide fade', 
     tags$div(
      class = 'modal-header', 
      HTML('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'), 
      tags$h3(label) 
     ), 
     tags$div(
      class = 'modal-body', 

      HTML(' 
       <form class="form-horizontal"> 
       <div class="control-group"> 
       <label class="control-label">Rows</label> 
       <div class="controls"> 
       <input type="number" class="tableinput-rowcount"> 
       </div> 
       </div> 
       <div class="control-group"> 
       <label class="control-label">Columns</label> 
       <div class="controls"> 
       <input type="number" class="tableinput-colcount"> 
       </div> 
       </div> 
       </form>' 
     ) 
     ), 
     tags$div(
      class = 'modal-footer', 
      tags$a(href = '#', class = 'btn btn-primary tableinput-edit', 'OK'), 
      tags$a(href = '#', 
       class = 'btn', 
       'data-dismiss' = 'modal', 
       'aria-hidden' = 'true', 
       'Cancel') 
     ) 
     ) 
    ) 
    ) 
} 

我希望这会帮助一些想要和我做同样事情的人。 如果有更多经验的人可以对rownames做些什么;这可能会很有趣。 (我在相关的主题阅读,这是一个有点困难比列名来做为matrixInput似乎不是丢弃它们只是隐藏)

来源:How to show/set row names to matrixInput (shinyIncubator)

从问题的repoducible例子可以用来试用它。

干杯

+0

如果有人用这个修改过的函数得到一个错误,在这里发布它,我们将尝试解决它 –