2017-01-11 4 views
0

光沢のあるアプリを作成しています。私はrhandsontableで生成されたテーブルでいくつかの行を色付けしたいと思います。Shinyのアプリケーション内で雲の色をカスタマイズする正しい方法

私はこの非常に良いチュートリアル、次のよ:具体的には、私はこの部分に興味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 instanceof Array ? hcols : [hcols] 
     hrows = tbl.params.row_highlight 
     hrows = hrows instanceof Array ? hrows : [hrows] 

     if (hcols.includes(col) && hrows.includes(row)) { 
     td.style.background = 'red'; 
     } 
     else if (hcols.includes(col)) { 
     td.style.background = 'lightgreen'; 
     } 
     else if (hrows.includes(row)) { 
     td.style.background = 'pink'; 
     } 

     return td; 
    }") 

このコードはRStudioで動作しますが、シャイニー上(表は単にdoesnのではありません表示されません)。

HTMLWidgets.widgets.filter(function(widget) { 
    // this should match the table id specified in the shiny app 
    return widget.name === "hot" 
})[0]; 

しかし、私はジャバスクリプトについて何も知らないので、私はどこへと少し迷ってしまいました:ウェブサイトでの説明は、シャイニーでこれを使用している場合、我々はコードにその部分を追加する必要があることを言って、ありますこの部分は行ってください。私は多くのことを試みました:

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); 
      HTMLWidgets.widgets.filter(function(widget) { 
      // this should match the table id specified in the shiny app 
      return widget.name === \"hot\" 
      })[0]; 
     .. 

しかし、それはまだ正しくありません。

これはおそらくjsに詳しい人にとっては非常に基本的な質問ですが、これを行う正しい方法は何ですか?

+0

Shiny(ui.Rとserver.R)で使用したコードを含めることはできますか? – MLavoie

答えて

1

列と行の色付けの簡単な例。

ui <- shinyUI(bootstrapPage(
    rHandsontableOutput("hot") 
)) 

server <- shinyServer(function(input, output) { 
    output$hot <- renderRHandsontable({ 
     DF = data.frame(val = 1:10, big = LETTERS[1:10]) 
     col_highlight = c(0, 1) 
     row_highlight = c(3) 

     rhandsontable(DF, col_highlight = col_highlight, row_highlight = row_highlight) %>% 
     hot_cols(renderer = " 
      function(instance, td, row, col, prop, value, cellProperties) { 
       Handsontable.NumericRenderer.apply(this, arguments); 
       if (instance.params) { 
        hcols = instance.params.col_highlight 
        hcols = hcols instanceof Array ? hcols : [hcols] 
        hrows = instance.params.row_highlight 
        hrows = hrows instanceof Array ? hrows : [hrows] 
       } 
       if (instance.params && hcols.includes(col)) td.style.background = 'red'; 
       if (instance.params && hrows.includes(row)) td.style.background = 'yellow'; 
      }") 
    }) 
}) 

shinyApp(ui, server) 
+0

はい、それは動作します。なぜ私はこのステップを行うと、通常、宝石類のチェックボックスとして表示されるブール値が文字列になるのか理解できません。これは、サイトの例のように、光沢のある外でも発生します。あなたは何か考えていますか? – Thiagogpsm

+1

ブーリアンは 'Handsontable.NumericRenderer.apply(this、arguments);;という行のために文字列になります。数値レンダリングでは数値と​​してレンダリングしようとします... 'Handsontable.TextCell.renderer.apply(this、arguments);しかし、それもブール値を台無しにする。あなたはそれをここで見ることができますhttps://jrowen.github.io/rhandsontable/#column_types最後の例 –

関連する問題