0

Hello Stackoverflow Commununity !

I am working on a Dashboard using Flexdashboard and Shiny. I want to introduce a filter on a graph. The dataframe used for the graph is the following :

date <- seq(as.Date("2017/1/1"), as.Date("2018/1/1"), by = "month")
date <- as.character(date[-1])
proto <- as.data.frame(matrix(c(1,1,1,2,2,3,3,3,3,4,4,4,
                            0,0,0,0,1,1,1,1,1,2,2,2,
                            5,5,5,6,6,7,7,7,7,7,8,8), ncol = 3, nrow =   length(date), byrow = F))

names(proto)[1] <- "cap_1"
names(proto)[2] <- "cap_2"
names(proto)[3] <- "cap_3"
row.names(proto) <- date
proto$total <- proto[,1] + proto[,2] + proto[,3] 

If I run the graph out of the shiny code, it works perfectly for each column and I obtain :

Ggplot Graph for the total column

Now, I try to put this graph into my dashboard with the objective to have a filter on the graph to select the column (cap_1, cap_2, cap_3 or total) to plot. Here is the code I used :

 ProtoUI <- function(id) {
  ns <- NS(id)
  fillCol(height = 600, flex = c(NA, 1), 
    inputPanel(
      selectInput(ns("cap"), "Capabilities:", choices = colnames(proto))
    ),
    plotOutput(ns("proto_plot"), height = "100%")
  )
}


Proto_serve <- function(input, output, session) {
  output$proto_plot <- renderPlot({
 ggplot(proto, aes(row.names(proto), input$cap, group = 1)) +
  geom_line(size=1.5, color="blue") + 
  labs(x = "Date", y = "Number of prototypes", title = " ") +
  geom_rangeframe() +
  theme_tufte() +
  theme(axis.text=element_text(size=12), 
axis.title=element_text(size=13,face="bold"))
   })
}

ProtoUI("proto")
callModule(Proto_serve, "proto")

And I obtain this graph : Graph in the dashboard

Normally, the line must not be constant but should follow the data of the dataframe for the column selected.

Thanks for sharing your knowledge to solve my issue =)

Flavien.

flavien
  • 1
  • 2

0 Answers0