我最近在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