我有一个闪亮的应用程序,打开时有一个简单的.bat文件,执行R,脚本在后台运行.R。有光泽的人用这个包裹
DT
以渲染所有表。我遇到的问题是,如果我从rstudiorun应用程序运行shiny,它会显示所有的表,但是如果我用.bat文件执行shiny,它就不会显示主题。我已经这样做了4次,这是第一次发生,我不知道问题。我有最新版本的
有CRAN,
所以我的
server.r
是:
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()
})
}
这个
ui.r
是
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"))))
))
run.r
是:
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)
"C:\Program Files\R\R-3.5.1\bin\R.exe" CMD BATCH "run.r"
如果我从
运行.r
这个
日期
要使其运行,您需要将server.r、ui.r、run.r和.bat保存在同一文件夹中。