R Shiny display full dataframe without filter input until filterinputs are changed

前端 未结 2 688
悲哀的现实
悲哀的现实 2020-12-22 01:26

I am trying to build an app which displays a dataframe as a datatable. I wanted to provide users with ability to subset the datatable with selectinput and daterangeinput fil

2条回答
  •  滥情空心
    2020-12-22 01:46

    Server.R

    shinyServer(function(input,output,session){
    
    
      data_update <- reactive({
    
        # Compose data frame
        data.frame(
          Name = c("Region", 
                   "Company",
                   "Status"),
          Value = as.character(c(input$region, 
                                 input$company,
                                 input$status)), 
          stringsAsFactors=FALSE)
      }) 
    
      # Show the values using an HTML table
      output$table <- renderTable({
        data_update()
      })
    })
    

    UI.R

    shinyUI(
      fluidPage(
        titlePanel("Summary"),
    
        sidebarLayout(
          sidebarPanel(
    
            selectInput("region", 
                        label = "Choose a Region",
                        choices = c("", unique(df$Region)), selected= '1'),
    
            selectInput("company", 
                        label = "Choose a company",
                        choices = c("", unique(df$Company)), selected= '1'),
    
            selectInput("status", 
                        label = "Choose Proj status",
                        choices = c("", unique(df$Status)), selected= '1'),
    
            dateRangeInput("projdate", 
                           label = "Date of interest:",
                           start = Sys.Date() - 60, 
                           end = Sys.Date())
          ),
    
          mainPanel(
            tableOutput("table")
          )
        )
      ))
    

    GLOBAL.R

    library(shiny)
    library(dplyr)
    library(DT)
    
    Region <- c("USA","UK","JPN","JPN","UK","USA","USA")
    Company <- c("A","B","C","A","B","C","A")
    Status <- c("Completed","In Production","In Design","New","In Production","In Design","New")
    date <- c("2015-05-01","2015-05-01","2015-06-04","2015-06-20","2015-07-15","2015-08-12","2015-08-12")
    date <- as.Date(date,"%Y-%m-%d")
    
    df <- data.frame(Region, Company, Status, date)
    

    I also recommend using DT package to plot your table.

    Hope it helps! Cheers

提交回复
热议问题