Open phoward38 opened 3 years ago
I also currently have trouble recreating a brushed chart in Shiny. The code works, when I use it in Rmarkdown. But if I move the code to two apexchartOutputs, than the smaller plot used for filtering blanks out.
Hello,
There's indeed a bug in shiny, unfortunately I haven't found a solution yet.
But here's an alternative using custom input and proxy to get the same result :
Live demo: https://dreamrs.shinyapps.io/example-brush-proxy/
library(shiny)
library(apexcharter)
data("economics", package = "ggplot2")
ui <- fluidPage(
fluidRow(
column(
width = 8, offset = 2,
tags$h2("Apexchart brush example (alternative) in Shiny", class = "text-center"),
apexchartOutput("brush_1"),
apexchartOutput("brush_2", height = "130px")
)
)
)
server <- function(input, output, session) {
output$brush_1 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line"
) %>%
ax_chart(
toolbar = list(
autoSelected = "pan",
show = FALSE
)
)
})
output$brush_2 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line"
) %>%
ax_chart(
brush = list(
enabled = TRUE
),
offsetY = -20,
selection = list(
enabled = TRUE
)
) %>%
ax_xaxis(labels = list(show = FALSE)) %>%
ax_yaxis(labels = list(show = FALSE)) %>%
set_input_selection(
inputId = "brush",
xmin = format_date(economics$date[1]),
xmax = format_date(economics$date[100])
)
})
observeEvent(input$brush, {
apexchartProxy("brush_1") %>%
ax_proxy_options(list(
xaxis = list(
min = as.numeric(input$brush$x$min) * 1000,
max = as.numeric(input$brush$x$max) * 1000
)
))
})
}
shinyApp(ui, server)
Victor
Really been enjoying this package as it keeps maturing, so just wanted to say thanks first!
I've created a minimal Shiny app with the Brush Chart example on your package's
github.io
, but the 2nd chart (w/ brush:enabled=TRUE
) doesn't show up until I open the browser's devtools. When I open it in Chrome, I'm getting the errorTypeError: Cannot read property 'w' of undefined
.Reprex:
global.R
server.R
ui.R
Oddly enough, the exact same chart works locally in another app of mine, but then once it's deployed to shinyapps.io or a GCP VM Instance, the same console error occurs.
Here's my session info (
GithubSHA1: bd179f978b27fb34e9ac5b8a206339fdb5465bbf
):