标签: rhandsontable

在rhandsontable单元格中插入控件输入和HTML小部件

我想rhandsontableshiny应用程序中将颜色选择器作为列类型.colourInput()colourpicker包中使用,我可以添加颜色选择器作为独立输入,从HTML标记创建它们,或将它们放在HTML表中(参见下面的示例代码).是否可以将颜色选择器输入控件添加到rhandsontable列?

最终目标是一个应用程序,允许用户从电子表格(如MS Excel)复制数据并粘贴到rhandsontable对象中,包括指定颜色名称或十六进制代码的文本.用户可以通过覆盖文本或通过光标操作从选择器中选择颜色来编辑颜色.该应用程序稍后将采用指定颜色的那些输入,执行计算和图形结果.

下面是一些示例代码,显示两次尝试失败.任何意见,将不胜感激.另外,我对JavaScript一无所知.该colourpickerrhandsontable护身符是优秀的资源,但我仍然无法弄清楚.

最小的例子

library(shiny); library(rhandsontable); library(colourpicker)

hotDF <- data.frame(Value = 1:4, Status = TRUE, Name = LETTERS[1:4],
                    Date = seq(from = Sys.Date(), by = "days", length.out = 4),
                    Colour = sapply(1:4, function(i) {
                      paste0(
                      '<div class="form-group shiny-input-container" 
                          data-shiny-input-type="colour">
                      <input id="myColour',i,'" type="text" 
                      class="form-control shiny-colour-input" data-init-value="#FFFFFF"
                      data-show-colour="both" data-palette="square"/>
                        </div>'
                      )}), stringsAsFactors = FALSE) 

testColourInput <- function(DF){
  ui <- shinyUI(fluidPage( rHandsontableOutput("hot") ))   
  server <- shinyServer(function(input, …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

15
推荐指数
1
解决办法
1143
查看次数

从 rhandsontable 对象中检索值(R,R 闪亮)

我使用(真棒)包 rhandsontable 稍后将包含在R闪亮网页中。用户可以在某些地方单击,我想知道如何检索有关单击哪些行的信息。这是一个示例,(在R终端中复制和粘贴):

library(rhandsontable)

## Create the dataset
min = c(1,seq(2,34,by=2))
kmh = c(0,seq(7,23,by=1))
mph = round( kmh / 1.609344, digits=0 )
stop.speed = rep(FALSE, length(min))    
DF = data.frame(min, kmh, mph, stop.speed, stringsAsFactors = FALSE)

#plot the table
r = rhandsontable(DF, useTypes = TRUE)
Run Code Online (Sandbox Code Playgroud)

我想过将其转换为R对象:

hot_to_r(r)

Error in (function (data, changes, params, ...)  : 
argument "params" is missing, with no default
Run Code Online (Sandbox Code Playgroud)

r dataframe shiny rhandsontable

6
推荐指数
1
解决办法
2340
查看次数

在 Shiny 应用程序中自定义 rhandsontable 颜色的正确方法

所以,我正在创建一个闪亮的应用程序,我想为使用 rhandsontable 生成的表中的一些行着色。

我正在关注这个非常好的教程:https : //jrowen.github.io/rhandsontable/

具体来说,我对这部分感兴趣:

library(rhandsontable)
DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
                small = letters[1:10],
                dt = seq(from = Sys.Date(), by = "days", length.out = 10),
                stringsAsFactors = FALSE)

col_highlight = 2
row_highlight = c(5, 7)

rhandsontable(DF, col_highlight = col_highlight, 
              row_highlight = row_highlight,
              width = 550, height = 300) %>%
  hot_cols(renderer = "
    function(instance, td, row, col, prop, value, cellProperties) {
      Handsontable.TextCell.renderer.apply(this, arguments);

      tbl = this.HTMLWidgets.widgets[0]

      hcols = tbl.params.col_highlight
      hcols = hcols …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

6
推荐指数
1
解决办法
2372
查看次数

使用rhandsontable在不同格式的反应数据集之间切换

在这个极好的问题中:Shiny:使用Rhandsontable和外部参数切换反应数据集,数据帧和rhandsontable输出具有相同的结构.

我正在尝试解决类似的问题,但是数据集没有相同的结构,并且数据集是在嵌套列表中构建的.考虑具有两个输入选择器的此示例:

列表和列表元素输入选择器

根据输入选择器,可以生成四种可能的表.他们是:

表1(清单1,"第一"):

第一张桌子

表2(清单1,"第二"):

第二张桌子

表3(清单2,"第三"):

第三表

表4(清单2,"第四"):

第四表

每个表通过renderRHandsontable元素出现在同一个位置.我认为我的问题在于更新reactiveValue"值" - 如何更新列表的元素而不更新任何其他元素?这是一个显示正确的最小示例,但您无法更改任何元素(我试图解决的问题).

require(rhandsontable)
require(shiny)

# Create some fake lists
list_1 <- list()
list_2 <- list()
list_1[['first']] <- data.frame(matrix(1:4,ncol=4))
list_1[['second']] <- data.frame(matrix(1:2,ncol=2),bool=factor('a1',levels=c('a1','a2','a3')))
list_2[['third']] <- data.frame(matrix(7:9,ncol=3))
list_2[['fourth']] <- data.frame(matrix(10:11,ncol=2),bool=factor('b1',levels=c('b1','b2')))

ui <- fluidPage(sidebarLayout(sidebarPanel(
  selectInput(
    'list_selector', 'Select list:',
    choices = c('list_1', 'list_2')
  ),
  uiOutput("second_selectorUI")
),
mainPanel(rHandsontableOutput("out"))))

server <- function(input, output) {

  values = reactiveValues()
  values[["list_1"]] <- list_1
  values[["list_2"]] <- list_2

  # Feed user input back to the list
  observe({
    if (!is.null(input$out)) {
      temp <- …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

6
推荐指数
1
解决办法
257
查看次数

有没有办法为 rhandsontable 中的不同行设置不同的下拉选项?

我正在制作一个闪亮的应用程序,用户需要在其中选择表格中的下拉选项。我正在使用 rhandsontable,但是似乎我只能为单个列设置一组下拉选项。所以第 1 行与第 800 行具有相同的选项。我希望第 1 行具有与第 800 行不同的下拉选项集。

有没有办法做到这一点?

我想过创建单独的表格并将它们放在一起看起来像一张桌子。只有第一个表会有列标题,它下面的所有其他表都没有列标题。我试图避免这种情况,因为 rhandsontables 具有水平和垂直滚动条,并且没有办法在多个表之间同步滚动条。那会让“一张桌子”看起来有点不对劲。实际上,将所有数据放在一个表中会更好看且功能更好。

我在下面有一个超级简单的例子:

  require(shiny)
  require(rhandsontable)

  ui <- fluidPage(
    hr(""),

    # Display table
    mainPanel(rHandsontableOutput("ExampleTable"))
  )

  server <- function(input, output) {

    output$ExampleTable <- renderRHandsontable({

      # creating table that will be displayed 
      df <- data.frame(Object = c("car", "car", "car", "house", "house", "house"), Needs = NA, stringsAsFactors = FALSE)

      # defining dropdown options
      dropdownOptions <- c("tires", "wipers", "headlights", "gutters", "carpet")

      rhandsontable(df, rowHeaders = NULL, stretchH = "all") %>%
        hot_col("Object", readOnly = TRUE) …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

6
推荐指数
1
解决办法
1074
查看次数

在 Shiny 应用程序中,rhandsontable 下拉菜单缩短了

当我尝试在 Shiny 应用程序中编辑 rhandsontable 的条目时,下拉菜单被缩短了。有没有办法让它们像rhandsontable 教程中的日期选择器一样完全扩展?这是应用程序。

library(rhandsontable)
library(shiny)

ui = fluidPage(rHandsontableOutput("data"))

server = function(input,output) {
  df = data.frame(x = factor(letters[1:3], levels = letters))
  values = reactiveValues(data = df)

  observe({
    req(input$data)
    values$data = hot_to_r(input$data)
  })

  output$data = renderRHandsontable({
    rhandsontable(values$data) 
  })
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

5
推荐指数
1
解决办法
1308
查看次数

闪亮的 RHandsontable 在闪亮的 modalDialog 中没有正确显示

我已经对这个问题进行了很多研究,但到目前为止,当使用 Shiny 的 showModal() 而不是 bsModal() 时,还没有提供解决方案。

当我第二次在模态对话框中显示rhandsontable时,显示有问题,即并非所有列都显示。

下面是一个例子:

library(shiny)
library(rhandsontable)

u <- shinyUI(fluidPage(

  # Will show first pop-up
  actionButton("go", "Show Table")

))

s <- shinyServer(function(input,output,session){

  df <- data.frame(Wnr = 1:10)  

  observeEvent(input$go, {

    output$table <- renderRHandsontable({

      rhandsontable(df, width = "100%", height = 200)

    })

    showModal(modalDialog(

      title = "Table",
      rHandsontableOutput("table"),
      footer = tagList(actionButton("go2", "Continue"),
                       modalButton("Stop"))

    ))
  })

  observeEvent(input$go2, {

    removeModal()

    # Recalculate the table, adding new columns
    output$table <- renderRHandsontable({

      df$AC <- 1
      df$BC <- …
Run Code Online (Sandbox Code Playgroud)

javascript modal-dialog shiny shinybs rhandsontable

5
推荐指数
0
解决办法
378
查看次数

将参数传递给rhandsontable中的自定义渲染器在Shiny应用程序中不起作用

我需要将一些参数传递给自定义rhandsontable渲染器中。它在 RStudio 中执行时工作正常,但在 Shiny 应用程序中使用时不会渲染任何内容。

以下是设置粗体字体的自定义渲染器的代码:

renderSheet <- function(df, bold) {
    rhandsontable(
        df,
        col_bold = bold$col,
        row_bold = bold$row) %>%  
    hot_cols(renderer = "
        function(instance, td, row, col, prop, value, cellProperties) {
          Handsontable.renderers.TextRenderer.apply(this, arguments);

          tbl = this.HTMLWidgets.widgets[0]

          col_bold = tbl.params.col_bold
          col_bold = col_bold instanceof Array ? col_bold : [col_bold] 
          row_bold = tbl.params.row_bold
          row_bold = row_bold instanceof Array ? row_bold : [row_bold] 

          if (col_bold.includes(col) && row_bold.includes(row)) {
            td.style.fontWeight = 'bold';
          }

          return td;
    }"
    ) }
Run Code Online (Sandbox Code Playgroud)

以下是在 RStudio 中运行它的方法:

df …
Run Code Online (Sandbox Code Playgroud)

javascript r shiny rhandsontable

5
推荐指数
0
解决办法
639
查看次数

rhandsontable,将文本换行在列的单元格中(和自动行高)

数据...

DF <- data.frame(a = c("hi", rep(NA, 4)),
                 b = letters[1:5],
                 c = LETTERS[1:5],
                 stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)

当我修复列宽和行高时,如何强制文本在单元格内换行(对于所有列或列的子集?)

rhandsontable(DF, stretchH = "all", height = 300 ) %>%
  hot_cols(colWidths = c(100, 50, 50),
           manualColumnMove = FALSE,
           manualColumnResize = TRUE
           ##, wordWrap = "yes please"
           ) %>%
  hot_rows(rowHeights = 75 ) %>%
  hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)
Run Code Online (Sandbox Code Playgroud)

更好的是,我可以将 rowHeight 保留为“自动”/默认值,并让它根据文本换行的需要进行扩展吗?

rhandsontable(DF, stretchH = "all", height = 300 ) %>%
  hot_cols(colWidths = c(100, 50, 50),
           manualColumnMove = FALSE,
           manualColumnResize = TRUE
           ##, …
Run Code Online (Sandbox Code Playgroud)

r shiny rhandsontable

5
推荐指数
1
解决办法
1985
查看次数

基于 rhandsontable 中的单元格值的颜色行

我正在努力根据单元格值在我闪亮的应用程序中为整行 rhandsontable 着色。

在下面的示例中,我想格式化整行而不是一个单元格。

library(rhandsontable)

DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
                small = letters[1:10],
                dt = seq(from = Sys.Date(), by = "days", length.out = 10),
                stringsAsFactors = FALSE)

col_highlight = 2
row_highlight = c(5, 7)

rhandsontable(DF, width = 550, height = 300) %>%
  hot_cols(renderer = "
               function (instance, td, row, col, prop, value, cellProperties) {
               Handsontable.renderers.TextRenderer.apply(this, arguments);

               if(value == 'F' | value == 'f') {
               td.style.background = 'pink';
               } else if(value == 'J' | value …
Run Code Online (Sandbox Code Playgroud)

r rhandsontable

4
推荐指数
1
解决办法
1424
查看次数

标签 统计

rhandsontable ×10

r ×9

shiny ×9

javascript ×2

dataframe ×1

modal-dialog ×1

shinybs ×1