0
votes

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.

1
You need to be consistent on what you call tabName (note the camelCase!). tabName = 'overview' and it works. We cannot comment on your data trans, as we don't have it.Martin
thanks for pointing that out but when I change it to lowercase, I still have basically a blank app. The input dates and the table do not show up. Im not allowed to share the trans table but all it is, is simply a data frame.Nick
@Martin I did not understand what you meant at first but now I see thank you. That indeed fixed the problem.Nick

1 Answers

1
votes

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)