I am building an R Shiny UI (split as UI and Server) which spends about three hours building a data.frame of disease clinical records given some Shiny UI parameters. On completion, the data.frame is passed to a Cox model and the result will be displayed as a plot.
When running R on the terminal the code will print information during those three hours e.g., how many patients/drugs it has parsed.
I have tried using separate textOutput UI features but I can't seem to get the textOutput to update from within a function call executed on the event of clicking a button. I believe this could be scope related. My code is split by UI and Server:
Note: the button is clicked once and I would like to see the textOutput to be updated several times on that click given a call from within a loop.
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("CPRD EHR Statistical Toolset"),
sidebarLayout(
sidebarPanel(
helpText("A long list of Input features below here."),
mainPanel(
h4("Medical record construction"),
textOutput("numPatientsOutput"),
actionButton("executeButton", "Execute Cox")
)
)
)
))
library(shiny)
shinyServer(function(input, output) {
observeEvent(input$executeButton, {
coxDF<-runBuildModel(input, output)
}) #endf of execute action
})
runBuildModel <- function(input, output) {
for(i in 1:10) {
#This is not updating.
output$numPatientsOutput <- renderText({paste("patient:",i)})
}
}