【发布时间】:2016-09-14 10:34:23
【问题描述】:
我最近在 r 中发现了 rhandsontable 包,它将在我的一些 r 闪亮项目中非常有用。我稍微修改了我在这里看到的Get selected rows of Rhandsontable 作为我将使用这个包的小测试器。 我希望能够让用户使用 rhandsontable 包从 r 中更改数据框的值。所以在这里我希望 df[1,1] 在每次更改该值时更新。当涉及到围绕渲染函数特别是 renderRHandsontable 函数包装反应函数时,我有点困惑。我在绘图中使用了反应函数,但这有点不同。
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 都反应性地操作。只是不确定正确的方法。
-
stackoverflow.com/questions/33722757/… ----- 很有帮助
标签: r shiny handsontable