2017-07-25 19 views
2

Formattable例えば、フォーマットテーブルにいくつかの簡単なオプションがあります。DT、formattableとshinyを組み合わせることは可能ですか?

library(shiny) 
library(DT) 
library(formattable) 

    df <- formattable(iris, lapply(1:4, function(col){ 

    area(col = col) ~ color_tile("red", "green") 

これは、後でそれがRStudionでビューアで表示するperfefect働く私にとってDTのDataTable

df <- as.datatable(df) 

にcovertedすることができます。しかし、私は何とかShinyアプリとして展開したいと思っています。完全なコード:

library(DT) 
library(shiny) 

ui <- fluidPage(
    DT::dataTableOutput("table1")) 


server <- function(input, output){ 

    df <- formattable(iris, lapply(1:4, function(col){ 

    area(col = col) ~ color_tile("red", "green") 

    })) 

    df <- as.datatable(df) 

    output$table1 <- DT::renderDataTable(DT::datatable(df)) 

} 

shinyApp(ui, server) 

これは機能しません、回避策はありますか?私はformattableから条件付き書式が好き、だけでなく、ちょうどformattableスレッドがあるとして、それを展開するには、いくつかのオプションフィルタリング例えばとしてDT提供、検索、colvisなど

を使用したい:

How to use R package "formattable" in shiny dashboard?

答えて

2

はい、可能であれば、hereと記載されているようです。

library(shiny) 
library(data.table) 
library(formattable) 

ui <- fluidPage(
    selectInput("input1","Species: ", choices = c("setosa", "versicolor", "virginica")), 
    DT::dataTableOutput("table1")) 

# make a data.table of the iris dataset. 
df <- iris 

server <- function(input, output){ 

    output$table1 <- DT::renderDataTable({ 

    my_df <- df[df$Species==input$input1,] 

    return(as.datatable(formattable(my_df, lapply(1:4, function(col){area(col = col) ~ color_tile("red", "green")})))) 
    } 
) 

} 

shinyApp(ui, server) 
+0

これを実行する方法についてのサンプルコードはありますか?私は貼り付けられた括弧のエラーをコピーしますが、すべてが大丈夫です... – MLEN

+0

申し訳ありませんが、それはうんざりです。 Stack Overflowにコピーしている間に私のコードを修正しましたが、括弧がありませんでした。私の更新された答えを見てください。 – Florian

+0

DTに追加引数を追加するにはどうすればよいですか?例えばエスケープのrownames。 – MLEN

関連する問題