如何在R Shiny中添加日期过滤器?

问题描述 投票:0回答:1

有人可以帮帮我吗,我在如何过滤日期上受阻?我不知道如何实现这一点。

而且我不知道如何将两个井板彼此紧挨着放置。不管我尝试了什么,它看起来都很可怕。

亲切的问候!

library(shiny)
library(dplyr)
library(DT)

{
  ui <- fluidPage(



    fluidRow(
      list(tags$head(HTML('<link rel="icon", href="fa.svg",
                                   type="image/svg" />'))),
      div(style="padding: 0px 0px; width: 0px; height: 0px",
          titlePanel(
            title="", windowTitle="Dashboard"
          )
      ),
      h2(id="title", "Dashboard"),
      tags$style(HTML("#title{color: white; background-color: #d52b1e; padding-left: 100px; padding-top: 18px; padding-bottom: 18px;}")) #font-weight: bold; 
    ),


    navlistPanel(
      tabPanel("D",
        fluidRow(
        # column(1), ## this put an extra space, dont like the look
        column(2,
               wellPanel(uiOutput("groups")),

        ),
        ),
        # fluidRow(
          column(2),
          column(2,
              wellPanel(
                 dateRangeInput('dateRange',
                                label = 'Filter op datum',
                                start = as.Date('2019-01-01') , end = as.Date('2019-12-31')
                 )
               ),
          ),
               column(2,
                      dataTableOutput('my_table')
               ),

        # ),
        # column(2)
      # ), ## this closes fluidrow below tabPanel 

      fluidRow(
        # column(1),
        column(8,
               tabsetPanel(type = "tabs",
                           # Tabbladen voor visueel of tabel
                           tabPanel("Staafdiagram",
                                    tags$br(),
                                    column(6,highchartOutput(outputId = "barPlot1", width="200%",height="450px")),
                                    # column(6,leafletOutput(outputId = "mapPlot", height=450)),
                           ),
                           tabPanel("Tabel en cijfers", 
                                    tags$br(),
                                    fluidRow(
                                      column(10,
                                             DT::dataTableOutput(outputId = "table1"), 
                                             downloadButton("downloadData", "Download")
                                      )
                                    ),
                                    tags$br(),
                                    fluidRow(
                                      column(6,p(id="disclaimtable","concept."),  tags$style(HTML("#disclaimtable{font-style: italic}")))
                                    )
                           ),
                           tabPanel("Help", 
                                    tags$br(),
                                    fluidRow(column(12
                                                    , class = "block"
                                                    , div(style = "padding-left:20px;padding-top: 15px; padding-bottom: 15px;"
                                                          , fluidRow("concept.")
                                                          , fluidRow("Heeft u vragen over dit dashboard of over andere mogelijkheden die u graag zou willen zien, neem dan contact op met: "
                                                                     , HTML("<a href='mailto:[email protected]'>anoniem</a>")))
                                    )
                                    ),
                           )
               )
        ),
        column(2)
      ),
    ),
      tabPanel("M"),
      tabPanel("Help"),
      tabPanel("Toelichting"),

      tabPanel("Component 5"),
      widths = c(1,10)
    ), ## this closes the navpanel




    fluidRow(tags$br())
  )
}

# De server met interactieve input
server <- function(input, output) {

   # Data klaarmaken voor barplot

  mydata_ <- reactive({
    data_ <- df2  # 
    data_
  })

  output$my_table  <- renderDataTable({
    # Filter the data
    df__<-my_data_()
    df2__%>% filter(AanvDat >= input$dateRange[1] & AanvDat <= input$dateRange[2])
  })



  output$groups <- renderUI({
    df_ <- mydata_()
    selectInput(inputId = "grouper", label = "Group variable", choices = c("L","LV","B","Naam","Omsch", "G"), selected = "L")
  })




  summary_data_ <- reactive({
    req(input$grouper)

    mydata_() %>%
      dplyr::group_by(!!!rlang::syms(input$grouper), Q) %>%
      dplyr::summarise(aantal = n()) %>%
      dplyr::arrange(desc(aantal)) %>%
      top_n(5)
  })

  output$barPlot1 <- renderHighchart({
    data_ <- summary_data_()
    hchart(data_, "column", hcaes(x = (!!input$grouper) , y = aantal , group = Q)) %>% 
      hc_plotOptions(column = list(stacking = "normal"))
  })

  # Data klaarmaken voor tabel
  mydata <- reactive({
    data <- df2  # 
    data
  })

  # output$groups <- renderUI({
  #   df <- mydata()
  #   selectInput(inputId = "grouper", label = "Group variable", choices = c("L","LV","B","Naam","Omsch", "G"), selected = "L")
  # })

  summary_data <- reactive({
    req(input$grouper)
    mydata() %>%
      dplyr::group_by(!!!rlang::syms(input$grouper)) %>%
      dplyr::summarise(aantal = n(),
                       Q = case_when(sum(Q =="TRUE") == length(Q) ~"JA", 
                                          sum(Q == "FALSE") == length(Q) ~"Nee",
                                          TRUE ~ "Beide"),
                       min_datum = as.Date(as.character(min(AanvDat))),
                       max_datum = as.Date(as.character(max(AanvDat))),%>%



      dplyr::arrange(desc(aantal)) 
  })

  output$table1 <- DT::renderDataTable({
    DT::datatable(summary_data())
  })

  # Downloadable csv of selected dataset ----
  output$downloadData <- downloadHandler(
    filename = function() {
      paste("O",Sys.Date(),".csv", sep = "")
    },
    content = function(file) {
      write.csv2(summary_data(), file, row.names = FALSE)
      write(paste("
        Dashboard-",Sys.Date(),"
        Deze tabel is nog in de conceptfase. D"
      ),file=file,append=TRUE)
    }
  )




# END
}

# Create Shiny app ----
shinyApp(ui, server)


我希望我的问题很清楚!提前致谢。

他们想让我添加更多的文本/细节,但是我不认为删除内容会更好。

r filter shiny shinydashboard datefilter
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.