I have a datatable and I would like to sequentially replace columns in the data based on the user's input - each user input choice will update a column from left to right. I read the documentation which indicates the replacement table must have the same number of columns as the table. I also looked at the example at the bottom of
http://rstudio.github.io/DT/shiny.html - I have a minimal example below based on my understanding but the table data is not replaced. In this example, I created two datatables one whose values are 2 and the other whose values are 4. I would assume the datatable that is rendered would have values of 4 since the table whose values are 2 has been replaced. What am I doing wrong?
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
DT::dataTableOutput("YieldAnalysis")
)
# Define server logic required to draw a histogram
DataTableOptions <- list(autowidth = TRUE,
searching = FALSE,
info = FALSE,
ordering = FALSE,
paging = FALSE)
YieldTable <- datatable(data = array(data = 2,
dim = c(9,7),
dimnames = list(c("Scenario",
"Life CPR",
"Yield",
"Avg. Life",
"Modified Duration",
"First Payment",
"Last Payment",
"Curve Spread",
"Zero Vol Spread"),
rep("Scenario",7)))
,options = DataTableOptions
,rownames = TRUE
,colnames = ""
,escape = TRUE)
YieldTableReplace <- array(data = 4, dim = c(9,7),
dimnames = list(c("Scenario",
"Life CPR",
"Yield",
"Avg. Life",
"Modified Duration",
"First Payment",
"Last Payment",
"Curve Spread",
"Zero Vol Spread"),
rep("Scenario",7)))
server <- function(input, output) {
output$YieldAnalysis <- renderDataTable({YieldTable})
YieldAnalysisProxy <- dataTableProxy("YieldAnalysis")
reactive({replaceData(YieldAnalysisProxy, YieldTableReplace)})
}
# Run the application
shinyApp(ui = ui, server = server)