Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heatmap in shiny: chart 'height' is not responsive #31

Closed
u909090 opened this issue Oct 30, 2020 · 2 comments
Closed

Heatmap in shiny: chart 'height' is not responsive #31

u909090 opened this issue Oct 30, 2020 · 2 comments

Comments

@u909090
Copy link

u909090 commented Oct 30, 2020

Hi,

No matter the value for apex(height = ...), the plot size does not change. Am I using the right argument or there is a bug?

Example:

library(shiny)
library(apexcharter)

data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)

ui <- fluidPage(
  radioButtons("height",
               label = "Heatmap Height",
               choiceNames = c("50px", "400px", "800px", "50%", "100%", "400", "1000"),
               choiceValues = c("50px", "400px", "800px", "50%", "100%", 400, 1000)
  ),
  apexchartOutput("heatmap")
)

server <- function(input, output) {
  output$heatmap <- renderApexchart({
    apex(df,
         aes(year, state, fill = count),
         type = "heatmap",
         height = input$height) %>% 
      ax_chart(animations = list(enabled = FALSE)) %>% 
      ax_dataLabels(enabled = FALSE)
  })
  
}

shinyApp(ui = ui, server = server)

Thanks !

@u909090
Copy link
Author

u909090 commented Oct 30, 2020

Specifying height in apexchartOutput() works, but in some cases it would be handier to modify the height directly when making the plot.

@pvictor
Copy link
Member

pvictor commented Dec 17, 2020

This is a common pattern for htmlwidgets, width and height are defined UI side, see example below for a workaround.
Note that using a percentage height won't work as is in CSS.

Use uiOutput \ renderUI to produce chart (will work only in recent version of Shiny):

library(shiny)
library(apexcharter)

data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)

ui <- fluidPage(
  radioButtons("height",
               label = "Heatmap Height",
               choiceNames = c("50px", "400px", "800px", "50%", "100%", "400", "1000"),
               choiceValues = c("50px", "400px", "800px", "50%", "100%", 400, 1000)
  ),
  uiOutput("heatmap")
)

server <- function(input, output) {
  output$heatmap <- renderUI({
    ax <- apex(df,
         aes(year, state, fill = count),
         type = "heatmap",
         height = input$height) %>% 
      ax_chart(animations = list(enabled = FALSE)) %>% 
      ax_dataLabels(enabled = FALSE)
    tags$div(ax)
  })
  
}

shinyApp(ui = ui, server = server)

Victor

@pvictor pvictor closed this as completed Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants