首页 文章

闪亮的仪表板DT :: renderDataTable ..输出没有渲染..在处理时被卡住...通过在选项中使其“FALSE”来修复它 . 但没有输出

提问于
浏览
0

我在闪亮的dashbaord中有两个tabpanel,其中一个(Tab - "Data Summary")表格被反应输出DT :: dataTableOutput . 在另一个(Tab - "Raw Data"),我只看到 Processing.... 但没有表格被渲染 . 所以在选项中添加了Processing = FALSE,这删除了处理.. banner ..但我看不到输出呈现 .

输入数据框:(dat)

Ad.ID   Coder

        75905818    deroy
        75910661    deroy
        75914385    deroy
        75902382    deroy
        75902383    jishuroy
        75902384    jishuroy
        75902386    jishuroy
        75902391    jishuroy
        75902393    jishuroy
        75902396    jishuroy
        75902418    jishuroy
        75902419    jishuroy
        75902421    jishuroy
        75902422    mrroy
        75902423    mrroy
        75902424    mrroy
        75902432    mrroy
        75902435    mrroy
        75902442    mrroy
        75902443    rande
        75902446    rande
        75902452    rande
        75902454    rande
        75914354    rande
        75914361    rande
        75915439    rande
        75915440    rande
        75915449    rande
        75915453    rande
        75915471    rande
        75915472    rande
        75915522    rande
        75905841    jishuroy
        75905842    mrroy
        75905867    mrroy
        75905869    mrroy
        75905870    deroy
        75905871    deroy
        75905887    deroy
        75905888    deroy
        75905889    deroy
        75905890    deroy

以下是我现在的代码 .

set.seed(4656)

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(DT)
library(plyr)
library(dplyr)
library(readr)

# Load data file & Model --------------------------------------------------

setwd("xxx....")

files <- list.files(pattern = '*.csv')    

y=NULL

for(i in files ) {
  x <- read.csv(i, header=TRUE, skip= 8,stringsAsFactors = FALSE)
  y= rbind(y,x)
}

dat <- y[,c(9,19)]

dat <- dat[!apply(is.na(dat) | dat == "", 1, all),]



# Simple header -----------------------------------------------------------

header <- dashboardHeader(title="Test)", titleWidth = 500)

# No sidebar --------------------------------------------------------------

sidebar <- dashboardSidebar(
  width = 300,

  sidebarMenu(
    menuItem("Inputs to Generate Audit Sample", icon = icon("list-ol"),
             # Input directly under menuItem

             pickerInput("in5","Coder", c(unique(as.character(dat$Coder))),options = list(`actions-box` = TRUE),multiple = T),
             numericInput("num", "Audit Sample (%)", value = 25) 
    )
  ),

  sidebarMenu( 
    menuItem("Export Audit Samples", icon=icon('download')),
    downloadButton("downloadData", "Download ...")    

  )  
)

# Compose dashboard body --------------------------------------------------

body <- dashboardBody(

  fluidRow(
    tabBox(
      title = "Testing",
      # The id lets us use input$tabset1 on the server to find the current tab
      id = "tabset1", height = "800px", width = "50px",
      tabPanel("Data Summary", DT::dataTableOutput("summary")),
      tabPanel("Raw Data", DT::dataTableOutput("table"))  
    )

  )
)

# Setup Shiny app UI components -------------------------------------------

ui <- dashboardPage(header, sidebar, body, skin="blue")

# Setup Shiny app back-end components -------------------------------------


server = function(input, output,session) {


  data <- reactive({

    validate(
      need(input$in5 != "Please Select Coder", "Please select Coder to view number of available records & sample count"))


    dist <- as((count(dat, "Coder")),"data.frame")

    dist$sample <- ceiling((dist[,2]*(input$num/100)))

    dist

    dist[dist$Coder %in% input$in5, ]

  })

  # Generate summary
  output$summary <- DT::renderDataTable({

    d <- data()

    DT::datatable(d, rownames = FALSE, escape = c(TRUE, FALSE, FALSE), 
                  caption = htmltools::tags$caption(
                    style = 'caption-side: top; text-align: center;',
                    'Team Selection: ', htmltools::em('Select your team by using picklist in agent column')),
                  #caption = 'Select your team by using picklist in agent column', 
                  colnames = c('Agent Name' = 'Coder', 'Number of Ads' = 'freq',"Sample Size"= 'sample'),
                  filter = 'top', options = list(pageLength = 15, autoWidth = TRUE)) 

  })



  data1 <- reactive({

    validate(
      need(input$in5 != "Please Select Coder", "Please select Coder to view number of available records & sample count"))


    names(dat)[2]<-"ID"

    observe({
      print("Renaming done")
    })


    per <-(input$num/100)

    observe({
      print("sample size captured")
    })

    new_df <- dat %>% group_by(ID) %>% sample_frac(per,replace = FALSE)

    observe({
      print("Samples generated")
    })

    new_df$ID <- gsub(" ", "", new_df$ID)

    observe({
      print("WhiteSpaces Removed")
    })

    inFile <- c(input$in5)

    observe({
      print("Input Filter Captured")
    })

    exp <- new_df[new_df$ID %in% inFile, ]

    observe({
      print("Ouptut Filtered")
    })

    exp

  })

  # Generate table of Samples
  output$table <- DT::renderDataTable({

    d1 <- data1()

 DT::datatable(d1, extensions = 'Responsive', rownames = FALSE, escape = c(TRUE, FALSE, FALSE), 
          caption = htmltools::tags$caption(
            style = 'caption-side: top; text-align: center;',
            'Team Selection: ', htmltools::em('Select your team by using picklist in agent column')),
          #caption = 'Select your team by using picklist in agent column', 
          # colnames = c('Agent Name' = 'Coder', 'Number of Ads' = 'freq',"Sample Size"= 'sample'),
          filter = 'top', options = list(pageLength = 15, autoWidth = TRUE,processing=FALSE)) 

  })



  # Downloadable csv of selected dataset ----
  output$downloadData <- downloadHandler(
    filename = function() {
      paste(c(input$in5), ".csv", sep = "")
    },
    content = function(file) {
      write.csv(exp, file, row.names = FALSE)
    }
  )

}
# Render Shiny app --------------------------------------------------------

shinyApp(ui, server)

在过去的30个小时里,我一直在为此烦恼..任何帮助都将是一个很大的帮助!!

2 回答

  • 0

    你的问题在于escape参数 . 您只有两列但三个值和数据表抛出错误消息 . 当您在控制台中运行它而不是在(Web)浏览器中时,您会注意到它 . 只需删除其中一个值即可完美运行

  • 0

    谢谢@Bertil,你的建议指出了我的问题 . 问题在于我试图过滤掉并捕获选择器输入的方式 .

    将现有代码更改为:

    per <-(input$num/100)
    
    newdf <- dat %>% group_by(Coder) %>% sample_frac(per,replace = FALSE)
    
    newdf
    
    newdf[newdf$Coder %in% input$in5, ]
    

    解决了!

相关问题