简体   繁体   中英

Creating table with date inputs in shinydashboard

My goal is to create a dashboard that has in one of the tabs a table based on date inputs from the user. I want this to be specifically in the tab called Overview in the dashboard.

I have 3 r scripts, one called data cleaning thats basically a table loaded into a data frame called trans . The other 2 are called ui and server. They are the following:

ui.R

library(shiny)
library(shinydashboard)
library(data.table)#For fread.
library(tidyverse)
library(DT)#For the interactive table.



# Header -----------------------------------------------------------------------|
header<-dashboardHeader( title = "Marketing Dashboard"
  
)


# Sidebar ----------------------------------------------------------------------|

sidebar<-dashboardSidebar(
  sidebarMenu(
    menuItem("Overview", tabname ="overview", icon = icon("dashboard")),
    menuItem("Weather", tabname ="weather", icon = icon("bolt"))
  )
)

# Body -------------------------------------------------------------------------|
  
body<-dashboardBody(
  tabItems(
    tabItem(tabName = 'Overview',
      fluidRow(     
        dateRangeInput("date",
          label = 'Date range input',
          start = Sys.Date() - 7, end = Sys.Date()
        ),
        dataTableOutput("overviewtable")
      )
    ),
    tabItem(tabName = 'weather',
      fluidRow(
        
      )
    )
  )
)



# UI ---------------------------------------------------------------------------|

ui = dashboardPage(
  header,
  sidebar,
  body
)

shinyApp(ui,server)


server.R

server <- function(input,output){
  
  #Reactive for dates in overview
  overviewdata<- reactive({
   trans %>% filter(ymd_hms(start_time) >= input$date[1] & ymd_hms(end_time)<= inpute$date[2])
  })
  #Table for overview
  output$overviewtable<- renderDataTable(
    datatable({
      overviewdata
    })
  )
  
  
}

My problem is when I run the app I see only a blank dashboard with two tabs. One for Overview and one for Weather. I don't see any table or any place where it gives me the option to input the dates. This is my first time working with shiny and I am trying to learn on the go. It is also my first time working with multiple r scripts. I have looked at other examples online from r gallery and from stack overflow but I am not sure what I am doing wrong.

You should place the dateRangeInput inside the menuItem if you want to see it inside the tab. Here's what it would look like under the "Overview" tab.

library(shiny)
library(shinydashboard)
library(data.table)#For fread.
library(tidyverse)
library(DT)#For the interactive table.



# Header -----------------------------------------------------------------------|
header<-dashboardHeader( title = "Marketing Dashboard"
                         
)


# Sidebar ----------------------------------------------------------------------|

sidebar<-dashboardSidebar(
  sidebarMenu(
    menuItem("Overview", tabname ="overview", icon = icon("dashboard"),
             dateRangeInput("date",
                            label = 'Date range input',
                            start = Sys.Date() - 7, end = Sys.Date()
             )),
    menuItem("Weather", tabname ="weather", icon = icon("bolt"))
  )
)

# Body -------------------------------------------------------------------------|

body<-dashboardBody(
  tabItems(
    tabItem(tabName = 'Overview',
            fluidRow(     
              dataTableOutput("overviewtable")
            )
    ),
    tabItem(tabName = 'weather',
            fluidRow(
              
            )
    )
  )
)



# UI ---------------------------------------------------------------------------|

ui = dashboardPage(
  header,
  sidebar,
  body
)

shinyApp(ui,server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM