闪亮错误,无输出

时间:2018-07-04 14:16:27

标签: r shiny shinydashboard

我必须创建一个仪表板,它将以csv文件作为输入,由用户提供,然后它将在选择一个变量后从实体列(设备和Uen)中选择变量,我们应该以uen的形式获取该变量数据用户数据文件中的列,然后选择1个uen数据,我们将获取该uen的所有变量数据

a = read.csv("input_missing.csv")
ui <- fluidPage ( 
tabsetPanel (
tabPanel("Input Data", fluid = TRUE,

         titlePanel(title=div( "Risk Rating Model", align = "center")),

         wellPanel(
           fluidRow(width = 2,column(width =  3, fileInput(  "file1", "Import the data file", accept = c(".csv"))),
                    column(width =  2, selectInput(  "file2", "Entity Details", c(" ", "Facility Id", "UEN "), selected=" ")),
                    column(width =  2, selectInput('FacilityId', 'Facility Id', a$CCDM_FacilityId)),
                    column(width =  2, selectInput('UEN', 'UEN Id', list(),, multiple = TRUE))
           ),

           fluidRow(
             DT::dataTableOutput("contents")


           )

         ))))

server <-function(input, output,session) { 

output$contents <- renderTable({

inFile <- input$file1

if (is.null(inFile))
  return(NULL)

read.csv(inFile$datapath, header = input$header)
 })




 observe({
updateSelectizeInput(session, "UEN", choices = a$input$file2)  
       })


 # Filter data based on selections
  output$contents <- DT::renderDataTable(DT::datatable({

if (input$FacilityId != "All") {
  a <- a[a$CCDM_FacilityId == input$FacilityId,]
}
if (input$UEN != "All") {
  a <- a[a$UEN1 == input$UEN,]
}


a
 }))

 }

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

尝试将第一个renderTable语句更改为这样的反应式语句

dta_table <- eventReactive(input$file1,{  
  inFile <- input$file1
  read.csv(inFile$datapath, header = input$header)
 })

然后将a <- dta_table()添加到第二次renderTable调用

output$contents <- DT::renderDataTable(DT::datatable({
  a <- dta_table()
  if (input$FacilityId != "All") {
    a <- a[a$CCDM_FacilityId == input$FacilityId,]
  }
  if (input$UEN != "All") {
    a <- a[a$UEN1 == input$UEN,]
  }
  a
}))

希望这会有所帮助!