-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.R
83 lines (71 loc) · 1.84 KB
/
log.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
library('shiny')
library('readr')
# Function to set home directory
defaultDir = '/home/user/cpls'
csf <- function() {
cmdArgs = commandArgs(trailingOnly = FALSE)
needle = "--file="
match = grep(needle, cmdArgs)
if (length(match) > 0) {
# Rscript via command line
return(normalizePath(sub(needle, "", cmdArgs[match])))
} else {
ls_vars = ls(sys.frames()[[1]])
if ("fileName" %in% ls_vars) {
# Source'd via RStudio
return(normalizePath(sys.frames()[[1]]$fileName))
} else {
if (!is.null(sys.frames()[[1]]$ofile)) {
# Source'd via R console
return(normalizePath(sys.frames()[[1]]$ofile))
} else {
# RStudio Run Selection
return(normalizePath(rstudioapi::getActiveDocumentContext()$path))
}
}
}
}
dir <- tryCatch(dirname(csf()),
error = function(e) {
defaultDir
}
)
if (is.null(dir) | length(dir) == 0) {
dir <- defaultDir
}
if(!dir.exists(dir)) {
err('Unable to determine home directory')
} else {
setwd(dir)
}
ui <- fluidPage(
titlePanel("System Log Viewer"),
wellPanel(fluidRow(
column(12,
dataTableOutput(outputId="log"),
br()
)
))
)
server <- function(input, output, session) {
data <- reactiveFileReader(1000,
session,
'store/system.log',
read_fwf,
skip=0,
fwf_positions( c(1,25,30),c(23,29,NA),c('Date','Priority','Message')))
output$log <- renderDataTable({
log <- data()
log$Date <- gsub('(\\[|\\])','',log$Date)
log
},options = list(pageLength = 100,
lengthMenu = c(100, 250, 1000),
order = c(0,'desc'),
autoWidth = TRUE,
columnDefs = list(
list(width = "140px", targets = 0),
list(width = "60px", targets = 1)
)
))
}
shinyApp(ui = ui, server = server)