I want to use rangeslider() with ggplotly(). Unfortunately, defining the start and end of the slider does not work with ggplotly(). I'm using the rangeslider() in the server.R of an RShiny App. In the server it looks like the following code snippet:
output$maForwardVsSpotPLOT <- renderPlotly({
plotFvsS <- MAForwardVsSpotMeanDifference(input$maStrategy, input$maTradingDays, input$maDateRange[1],
input$maDateRange[2], input$maPeriod)$FvsSMeanDiffPlot
ggplotly(plotFvsS, dynamicTicks = TRUE) %>%
rangeslider() %>% # start = input$maDateRange[1], end = input$maDateRange[2]
layout(hovermode = "x")
})
In the UI I have:
tabItem(tabName = "maForwardVsSpot",
fluidRow(width = 7, dateRangeInput(inputId = "maFFDateRange", label = "Date Range",
start = "2018-01-01", end = Sys.Date()),
fluidRow(width = 7, plotlyOutput(outputId = "maForwardVsSpotPLOT", width = "900px",
height = "600px")
plotFvsS is defined in an external function (MAForwardVsSpotMeanDifference) and looks like this:
plotFvsS <- ggplot(dt.allDataFvsS, aes(x = date, y = meanDifference)) +
coord_cartesian(ylim = c(-25, 25)) + # Note: using ylim throws all data outside of ylim away!!! using coord_cartesian solves this problem
ggtitle("Price Difference Forward vs. Spot") +
geom_line(color = "blue", size = 0.9) +
labs(y = "EUR/MWh", x = "Date") +
theme(axis.text = element_text(size = 9), axis.title = element_text(size = 5),
panel.grid.minor = element_blank(), panel.grid.major = element_blank(),
panel.border = element_rect(fill = NA, color = "black", size = 1)) +
theme_bw(base_size = 17) +
theme(panel.grid.minor = element_blank(), panel.grid.major = element_blank()) +
geom_hline(yintercept = 0, color = "black") +
geom_hline(yintercept = c(20,10,-10,-20), color = "#CCCCCC") +
geom_vline(xintercept = c(12481, 12784, 13149, 13514, 13879, 14245, 14610, 14975, 15340, 15706,
16071, 16436, 16801, 17167, 17532, 17897, 18262, 18628)) +
geom_vline(xintercept = c(12509, 12600, 12692, 12874, 12965, 13057, 13239, 13330, 13422, 13604,
13695, 13787, 13970, 14061, 14153, 14335, 14426, 14528, 14700, 14791,
14883, 15065, 15156, 15248, 15431, 15522, 15614, 15796, 15887, 15979,
16161, 16252, 16344, 16526, 16617, 16709, 16892, 16983, 17075, 17257,
17348, 17440, 17622, 17713, 17987, 18078, 18170, 18353, 18444, 18536),
linetype = "dashed", color = "#666666") +
geom_vline(xintercept = 17805, linetype = "dashed", color = "red")
How can I add start and end in the rangeslider()?