2016-11-17 27 views
0
ui <- fluidPage(

    # Application title 
# titlePanel("Old Faithful Geyser Data"), 

    mainPanel(
    rHandsontableOutput('table'), 
    br(), 
    submitButton("Apply changes"), 
    verbatimTextOutput('selected') 
    ) 

) 

server <- function(input, output) { 
     data1 = read.csv("SampleCSVFile_2kb.csv", TRUE,",") 


     output$table = renderRHandsontable(rhandsontable(data1, width = 1000, height = 250)) 

     output$selected=renderPrint({ 
     cat('\nChanged Cell Old Value:',input$table$changes$changes[[1]][[3]]) 
     cat('\nChanged Cell New Value:',input$table$changes$changes[[1]][[4]]) 
     }) 
    } 

shinyApp(ui = ui, server = server) 
+0

你的意思是你想更新'input $ table'?目前還不清楚你實際想要更新什麼。你能否詳述一下你想達到的目標? – SBista

+0

是的,確切地說。我想更新輸入$表。 –

回答

1

據我所知,當你按下提交按鈕時,你想訪問你服務器內的rhandsontable輸入。 在下面的示例中,我修改了代碼,以便在tableoutput中顯示更新的rhandsontable。

library(shiny) 
library(rhandsontable) 

ui <- fluidPage(

    # Application title # titlePanel("Old Faithful Geyser Data"), 

    mainPanel(
    rHandsontableOutput('table'), 
    br(), 
    submitButton("Apply changes"), 
    verbatimTextOutput('selected'), 
    ##The updated table output 
    rHandsontableOutput('tableoutput') 
) 
) 


server <- function(input, output) { 
    data1 = read.csv("SampleCSVFile_2kb.csv", TRUE,",") 


    output$table = renderRHandsontable(rhandsontable(data1, width = 1000, height = 250)) 

    output$selected=renderPrint({ 
    cat('\nChanged Cell Old Value:',input$table$changes$changes[[1]][[3]]) 
    cat('\nChanged Cell New Value:',input$table$changes$changes[[1]][[4]]) 
    }) 

    observe(
    if(!is.null(input$table)){ 
     output$tableoutput = renderRHandsontable(rhandsontable(hot_to_r(input$table), width = 1000, height = 250)) 


    } 
    ) 

} 


shinyApp(ui = ui, server = server) 

希望它有幫助!

+0

它工作。謝謝@SBista。你能解釋hot_to_r函數嗎? –

+0

@Ishanmahajan'hot_to_r'函數用於將rhandsontable對象轉換爲R對象(數據框)。 – SBista

相關問題