@Aviansh you did not define the behaviour for the save button. If you just want to save the data to disk, you can do it like this
library(shiny)
library(shinydashboard)
library(rhandsontable)
header<-dashboardHeader()
sidebar <- dashboardSidebar()
#Creation of Tabs
body <- dashboardBody(
tabBox( width=12,
tabPanel("Table",
rHandsontableOutput("hot"),
br(),
br(),
actionButton("save","Save changes")
),
tabPanel("Demand/Capacity Plot",
plotOutput("dc","Demand Capacity Plot",width="50%", height="700px")
)
)
)
ui <- dashboardPage(header,sidebar=sidebar,body=body)
table_l1<- data.frame(Months=1:14,Bt_existing=numeric(14),Output_hr=numeric(14),stringsAsFactors = FALSE)
server <- function(input, output, session){
prev_tabl_l1 <- reactive({table_l1})
aftch_tabl_l1<- reactive({
if (is.null(input$hot)){
return(prev_tabl_l1())
} else if(!identical(prev_tabl_l1(),input$hot)){
table_l1<-as.data.frame(hot_to_r(input$hot))
table_l1[,3]<-3600/table_l1[,2]
table_l1
}
})
output$hot <- renderRHandsontable({
rhandsontable (aftch_tabl_l1(),rowHeaders =c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Year 1","year 2"),width= 500, height=200,selectCallback = TRUE) %>%
hot_table(rowHeaderWidth = 200) %>%
hot_col(1,readOnly = TRUE)
})
observeEvent(input$save,{
hot <- isolate(input$hot)
if(!is.null(hot)){
fname = tempfile(fileext = ".csv")
write.csv(hot_to_r(hot), fname)
print(paste("Saved to", fname))
}
})
}
shinyApp(ui=ui, server=server)