I am trying to get a Shiny dashboard although my graph will not work.
I have a data.frame consisting of a Date
column in date format and 4 numeric column types which are ISA, NonISA, FixedRateInterest and VariableRateInterest
and have filled the N/A values with 0.
I have checkboxes with a date range slider and I can get the graph to render but when I try and add in the DateRangeslider it doesn't not work and throws the following error:
Unknown input:data.frame
This is my code to create the dashboard. Can anyone help me understand why it is not working please? I know it has something to do with the ggplot line but not sure what.
Thanks
isa <- read.csv("isa.csv")
isa$Date <- paste0(isa$Date, "01")
isa$Date <- as.character(isa$Date)
isa$Date <- as.Date(isa$Date, format = "%Y%m%d")
date <- isa$Date
# Define UI ----
ui <- fluidPage(
titlePanel("Customer"),
sidebarLayout(
sidebarPanel(
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
img(src = "Logo.jpg", height = 100, width = 150)),
fluidRow(
h1("Choose Dataset"),
br(),
br(),
column(1,
checkboxGroupInput(inputId = "product",
h3("Product"),
choices = c('ISA',
"Non-ISA",
"Fixed",
"Variable"),
selected = 1)),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
column(2,
dateRangeInput(inputId = "dates", h3("Date Range"),
start = min(isa$Date),
end = max(isa$Date),
min = min(isa$Date),
max = max(isa$Date),
separator = "-", format = "yyyy/mm/dd")
))),
br(),
br(),
br(),
mainPanel(
plotOutput("barplot")
)
)
)
# Define server logic ----
server <- function(input, output) {
dataInput <- reactive({
switch(input$product,
"ISA" = ISA,
"Non-ISA" = isa$NonISA,
"Fixed" = isa$FixedRateInterest,
"Variable" = isa$VariableRateInterest)
It Is here that it seems to fail
})
dateInputx <- reactive({
isa[isa$Date >= input$dates[1] & isa$Date <= input$dates[2],]
})
output$barplot <- renderPlot({
And doesn't recognise the x axis on ggplot
ggplot(data = dataInput(), aes_string(x= dateInputx(), y = dataInput())) +
geom_line(stat ="identity")
})
}
# Run the app ----
shinyApp(ui = ui, server = server)