R 仅当数据加载到应用程序中时显示框

R 仅当数据加载到应用程序中时显示框,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我已经做了一个闪亮的应用程序,我想上传并显示在它旁边。因为我的数据会很大,所以我让它可以滚动并放在一个盒子里 现在,我只想在加载数据时显示该框 我试过条件面板,但没用 这是密码 用户界面 库(闪亮) 图书馆(shinydashboard) 图书馆(DT) 图书馆(ggvis) 图书馆(闪亮) ui您可以使用renderUI并对数据进行条件输出: # ui.R column(9,uiOutput("box")) # server.R output[["box"]] <- rend

我已经做了一个闪亮的应用程序,我想上传并显示在它旁边。因为我的数据会很大,所以我让它可以滚动并放在一个盒子里

现在,我只想在加载数据时显示该框

我试过条件面板,但没用

这是密码

用户界面

库(闪亮)
图书馆(shinydashboard)
图书馆(DT)
图书馆(ggvis)
图书馆(闪亮)

ui您可以使用
renderUI
并对数据进行条件输出:

# ui.R
  column(9,uiOutput("box"))

# server.R
  output[["box"]] <- renderUI({

    if(is.null(theData()))return()
    box(
      title = "Data", width = NULL, status = "primary",
      div(style = 'overflow-x: scroll;', DT::dataTableOutput('contents'))
    )

  })
#ui.R
列(9,uiOutput(“框”))
#服务器.R
输出[[“框”]]
shinyServer(function(input, output, session) {
  #load the data when the user inputs a file
  theData <- reactive({
    infile <- input$file1        
    if(is.null(infile))
      return(NULL)        
    d <- read.csv(infile$datapath, header = T)
    d        
  })

  output$contents <- DT::renderDataTable({
    data1 <- theData()
  })

  # dynamic variable names
  observe({
    data<-theData()
    updateSelectInput(session, 'y', choices = names(data))
  }) 
  #gets the y variable name, will be used to change the plot legends
  yVarName<-reactive({
    input$y
  }) 
})
# ui.R
  column(9,uiOutput("box"))

# server.R
  output[["box"]] <- renderUI({

    if(is.null(theData()))return()
    box(
      title = "Data", width = NULL, status = "primary",
      div(style = 'overflow-x: scroll;', DT::dataTableOutput('contents'))
    )

  })