我最近在r中發現了rhandsontable包,它將在我的一些r閃亮項目中非常有用。我稍微修改了我在這裏看到的Get selected rows of Rhandsontable作爲我將使用此包的一個小測試器。 我希望能夠讓用戶使用rhandsontable包更改r內的數據幀的值。因此,我希望每次更改該值時都要更新df [1,1]。當我們圍繞渲染函數,特別是renderRHandsontable函數封裝一個反應函數時,我感到有點困惑。我用繪圖功能使用了反應函數,但這有些不同。反應性和rhandsontable
library(shiny)
library(rhandsontable)
ui=fluidPage(
rHandsontableOutput('table'),
verbatimTextOutput('selected'),
verbatimTextOutput("tr")
)
server=function(input,output,session)({
a<-c(1,2)
b<-c(3,4)
c<-rbind(df1,df2)
df1<-data.frame(df3)
#need reactive function around the following
output$table=renderRHandsontable(
rhandsontable(df1,selectCallback = TRUE,readOnly = FALSE)
)
output$selected=renderPrint({
cat('Selected Row:',input$table_select$select$r)
cat('\nSelected Column:',input$table_select$select$c)
cat('\nSelected Cell Value:',input$table_select$data[[input$table_select$select$r]][[input$table_select$select$c]])
df1[input$table_select$select$r,input$table_select$select$c]<-input$table_select$data[[input$table_select$select$r]][[input$table_select$select$c]]
})
#need reactive function around the following
output$tr <- renderText({
df1[1,1]
})
})
# end server
shinyApp(ui = ui, server = server)
這是一個有趣的領域,將在我閃亮的應用中打開很多,供用戶隨意使用。
謝謝
我相信我需要df1和renderRHandsontable都是反應性操作。只是不確定正確的做法。 – mike
http://stackoverflow.com/questions/33722757/update-handsontable-by-editing-table-and-or-eventreactive -----非常有幫助 – mike