我在访问从rhandsontable包创建的数据框的各个值时遇到问题。在下面的代码中, co[1]
检索合理的第1列,但后来我尝试访问 col[1,1]
第1行第1列产生 missing value where TRUE/FALSE needed which is a bizarre error in this circumstance.
我尝试使用列表方法 co[[[1]][1]
访问它,但没有运气。
library(shiny)
library(rhandsontable)
did_recalc <- FALSE
ui <- fluidPage(
rHandsontableOutput('table'),
dataTableOutput('result'),
br(),
# tableOutput(),
actionButton("recalc", "Return to original values")
)
server <- function(input,output,session)({
a<-c(1,2,4,5,6,7)
b<-c(1,2,4,5,6,7)
c<-rbind(a,b)
df1<-data.frame(c)
#creates reactive values for the data frame
values <- reactiveValues(data=df1)
#if recalc --- which connects to an action button in the ui is hit, values goes back to original data frame
observe({
input$recalc
values$data <- df1
})
#this changes the handsontable format to an r object
observe({
if(!is.null(input$table))
values$data <- hot_to_r(input$table)
})
#important that you are using the values$data that have come from a reactive function
output$table <- renderRHandsontable({
rhandsontable(values$data)
})
fn<-reactive({
co<-data.frame((values$data))
#output$tst<-renderTable(co[3,2]*2) #So if I convert to a new data frame I can do operations on the columns
#Still need to be able to access individual cells
return(co)
})
output$result<-renderDataTable({
fn()
})
})
shinyApp(ui = ui, server = server)
我觉得我试图访问的对象不像我假设的那样干净或结构化。