My requirement is to run a script from shiny app whenever a button is clicked and show the results in the UI after the script run.
I tried the below inside the server but the UI shows the updated results only if I reload the app.
source("recalculate.R", local = TRUE)
And the below is not working at all.
observeEvent(input$recalculatebtn, source("recalculate.R", local = TRUE))
Can anyone please help me to sort this out?
Adding the below a very basic sample case.
Data:
TableA = data.frame(A = c(1:3), B = c(4:6))
Recalculate.R:
TableC = data.frame(C = TableA$A * TableA$B)
UI:
ui = shinyUI(
fluidPage(
sidebarPanel(
conditionalPanel(condition = "input.tabselected == 'tab1'", actionButton("recalcbtn", "Recalculate"))
),
mainPanel(uiOutput("mainpanel"))
)
)
Server:
server = function(input, output, session) {
output$mainpanel = renderUI({
tabsetPanel(
tabPanel("ModifyTableA", value = 'tab1', rHandsontableOutput("OTableA")),
tabPanel("UpdatedValues", value = 'tab2', DT::dataTableOutput("OTableC")),
id ="tabselected"
)
})
indat <- reactiveValues(data=TableA)
output$OTableA =
renderRHandsontable({
indat$data <- TableA
rhandsontable(indat$data)
})
output$OTableC = DT::renderDataTable(TableC)
observeEvent(input$recalcbtn,
{
TableA <<- input$OTableA
source("Recalculate.R", local = TRUE))
}
}