简体   繁体   English

DT 表未显示为闪亮

[英]DT tables not shown in shiny

I have a shiny app that opens with a simple .bat file that executes R and the script run.r in the background.我有一个闪亮的应用程序,它打开一个简单的 .bat 文件,该文件在后台执行 R 和脚本 run.r。 The shiny use the package DT extensively to render all the tables. DT广泛使用包DT来呈现所有表格。 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.我遇到的问题是,如果我从 Rstudio run app 运行 Shiny,它会显示所有表格,但是如果我使用 .bat 文件执行 Shiny,它就不会显示主题。 I have done this like 4 times and it is the first time it happens and I don't know the problem.我已经这样做了 4 次,这是第一次发生,我不知道问题所在。 I have the latest version of the pacakges of the DT available in CRAN,我有 CRAN 中可用的DT pacakges 的最新版本,

So my server.r is :所以我的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()
  })  
}

the ui.r is 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"))))
  ))

the run.r is: 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)

and the .bat file contains: .bat 文件包含:

"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.如果我从run.r运行闪亮的应用程序,则显示DT ,但如果我从 .bat 文件运行它,则不会。 To make it run you will need to save the server.r, ui.r, run.r and .bat in the same folder.要使其运行,您需要将 server.r、ui.r、run.r 和 .bat 保存在同一文件夹中。

If you read RStudio's page on Using DT in Shiny , you may not have noticed如果您阅读了 RStudio 的在 Shiny 中使用 DT的页面,您可能没有注意到

Note that in DT , DTOutput() is an alias of dataTableOutput() , and renderDT() is an alias of renderDataTable() .请注意,在DT, DTOutput()是一个别名dataTableOutput()renderDT()是一个别名renderDataTable() You are recommended to use DTOutput() and renderDT() to avoid possible collisions with functions of the same names in shiny ( shiny::dataTableOutput() and shiny::renderDataTable() ).建议您使用DTOutput()renderDT()以避免闪亮名称相同的功能可能的碰撞( shiny::dataTableOutput()shiny::renderDataTable()

Collisions, that's your problem.碰撞,那是你的问题。 To confirm, if you see this:确认一下,如果你看到这个:

find("dataTableOutput")
# [1] "package:DT"    "package:shiny"
find("renderDataTable")
# [1] "package:DT"    "package:shiny"

then the function name collision is likely to blame.那么函数名冲突很可能是罪魁祸首。 Try replacing your dataTableOutput(...) with either DT::dataTableOutput(...) or DTOutput(...) ;尝试用DT::dataTableOutput(...)DTOutput(...)替换你的dataTableOutput(...) DTOutput(...) and replace renderDataTable(...) with either DT::renderDataTable(...) or renderDT(...) .并将renderDataTable(...)替换为DT::renderDataTable(...)renderDT(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM