2017-05-12 8 views
1

私は次のコードを持っています。私はそう光沢のあるRスタジオのアクションボタンを使って酷使可能なオブジェクトの欠損値を埋めてください

datacopy[16, "wt"]= datacopy[16, "mpg"] + datacopy[16, "cyl"]

としての価値を計算する関係を考えると、「行く」ボタンをクリックされると太字番号(または赤の色でもあります)でrhandsontableオブジェクトの欠損値を埋めたいです出力テーブルは欠損値なしで救済可能でなければならない(欠損値は置き換えられる)。私はこれをどのようにすることができるか誰にも分かりますか?どうもありがとうございました。 :)

library(shiny) 
library(datasets) 
library(rhandsontable) 

ui=fluidPage(

br(), br(), actionButton("update", "go", class="success"), br(), br(), 
rHandsontableOutput("table1") 
) 


server=function(input, output, session) { 

mt=reactive({ 

datacopy= data.table(mtcars) 
datacopy[16, "wt"] <- NA 
datacopy 

}) 

output$table1=renderRHandsontable({ 
rhandsontable(mt()) 
}) 

} 

shinyApp(ui,server) 

答えて

1

これは何ですか?ボタンをトリガーしてテーブルを再描画するためにobserveEventを追加しました。また、私はとてもその簡単に

library(shiny) 
library(rhandsontable) 

ui <- fluidPage(

    br(), br(), actionButton("update", "go", class="success"), br(), br(), 
    rHandsontableOutput("table1") 
) 

server=function(input, output, session) { 

    mydata <- reactiveValues() 
    mydata$data <- mtcars 

    observeEvent(input$update,{ 
    mydata$data[16, "wt"] <- NA 
    }) 

    output$table1 <- renderRHandsontable({ 
    rhandsontable(mydata$data) %>% 
     hot_cols(renderer = " 
       function (instance, td, row, col, prop, value, cellProperties) { 
       Handsontable.renderers.NumericRenderer.apply(this, arguments); 
       if (value== 'NA') { 
       td.style.background = 'pink';} 
       }") 
    }) 
} 

shinyApp(ui,server) 

enter image description here

編集を操作するためreactiveValuesにあなたのデータセットを包ん:前に大胆かつ代替NAで式

library(shiny) 
library(rhandsontable) 

ui <- fluidPage(
    br(), br(), actionButton("update", "go", class="success"), br(), br(), 
    rHandsontableOutput("table1") 
) 

server=function(input, output, session) { 
    mtcars[16, "wt"] <- NA 

    mydata <- reactiveValues() 
    mydata$data <- mtcars 
    #mydata$data[16, "wt"] <- NA 

    observeEvent(input$update,{ 
    mydata$data[16, "wt"] <- mydata$data[16, "mpg"] + mydata$data[16, "cyl"] 
    }) 

    output$table1 <- renderRHandsontable({ 
    rhandsontable(mydata$data) %>% 
     hot_cols(renderer = " 
       function (instance, td, row, col, prop, value, cellProperties) { 
       Handsontable.renderers.NumericRenderer.apply(this, arguments); 
       if (value== 'NA') { 
       td.style.fontWeight = 'bold';} 
       }") 
    }) 
    } 

shinyApp(ui,server) 

により算出した値をNAを追加します。クリック: enter image description here

はをクリックした後、NAの値は18.40に変更:

enter image description here

+0

はどうもありがとうございました。ピンクの背景の代わりに、太字のNAでどのように修正できますか? – Sumeda

+0

また、「go」ボタンをクリックするとdatacopy [16、 "wt"] = datacopy [16、 "mpg"] + datacopy [16、 "cyl"]という式を追加して欠損値を計算する方法はありますか? – Sumeda

+0

これは私が望むものではありません。 "Go"ボタンをクリックすると、datacopy [16、 "wt"] = datacopy [16、 "mpg"] + datacopy [16、 "cyl"]という式にしたがって欠損値を評価する必要があります。 – Sumeda

関連する問題