I have a very simple Shiny app to show the CPU usage and available memory of the shiny server :
ui <- fluidPage(
titlePanel('Shiny Server Monitor'),
DT::dataTableOutput("cpu")
)
server <- function(input, output, session) {
output$cpu <- DT::renderDataTable({
invalidateLater(1000)
system("free -h > top.log")
system("uptime > uptime.log")
free <- readLines("top.log")
uptime <- readLines("uptime.log")
mem = strsplit(free, "")
available_mem =tail(mem[[2]],n=1)
# I have 6 cores so normalized by deviding the load avarage to 6.
load_ave = round(as.numeric(unlist(strsplit(unlist(strsplit(uptime, ","))[4],":"))[2])/6*100,2)
dat = data.frame(load_ave,available_mem)
colnames(dat) = c("CPU usage [%]", "Available memory [Gb]")
DT::datatable(dat,rownames= FALSE)
})
}
Since I'm using the invalidateLater
command the output table is updating every second and therefore is blinking, which make everything very ugly.
Is there a way to fix this issue or present the result (especially the CPU usage) as htop
command in Linux like :