I have a shiny app that opens with a simple .bat file that executes R and the script run.r in the background. The shiny use the package DT
extensively to render all the tables. The problem i'm having is that if i run the shiny from Rstudio run app it shows all the tables but if I execute the shiny with the .bat file it just doesn't show theme. I have done this like 4 times and it is the first time it happens and I don't know the problem. I have the latest version of the pacakges of the DT
available in CRAN,
So my server.r
is :
server <- function(input, output,session) {
observeEvent(input$run,{
TablasVaR <- function(mat,DT = T){
mat_tbl <- data.frame(Activos = rownames(mat),Porcentaje = mat[,"Porcentaje"],
VaR = mat[,"Nivel"])
tabla <- datatable(mat_tbl, escape = T,rownames = FALSE,
selection = list(target = 'row'),
options = list(dom = 'tip', paging = TRUE))%>%
formatStyle(1:ncol(mat_tbl),fontSize = '100%')%>%
formatCurrency(3,digits = 0)%>%
formatPercentage(2,digits = 1)
if(DT){
return(tabla)
} else{
return(mat_tbl)
}
}
matr <- data.frame(Porcentaje=rnorm(19),Nivel = rnorm(19))
output$table <- renderDataTable({TablasVaR(matr)})
})
session$onSessionEnded(function() {
stopApp()
})
}
the ui.r
is
ui <- fluidPage(
sidebarLayout(
sidebarPanel(),
wellPanel(style = "background-color: #ffffff;",
bsButton("run","run1",block=F, style="default"),
fluidRow(column(4,align="center",offset = 4,
dataTableOutput("table"))))
))
the run.r
is:
librerias <- c("openxlsx","ggplot2","scales","rugarch","zoo","data.table","stringr",
"DT","plotly","lubridate","knitr","gridExtra","grid","shinyBS",
"rmarkdown","nloptr","shiny")
if(length(setdiff(librerias, rownames(installed.packages()))) > 0){
install.packages(setdiff(librerias, rownames(installed.packages())))
}
invisible(sapply(librerias, require, character.only = TRUE))
CAMINO <<- "D:/Users/aandr/Documents/Ejemplo/"
runApp(CAMINO, launch.browser=TRUE)
and the .bat file contains:
"C:\Program Files\R\R-3.5.1\bin\R.exe" CMD BATCH "run.r"
if I run the shiny app from the run.r
the DT
is display, but if I run it from the .bat file it wont.
To make it run you will need to save the server.r, ui.r, run.r and .bat in the same folder.