首页 > 解决方案 > ggplot plot from esquisse package not rendering in flexdashboard

问题描述

When I try to include the excellent esquisse shinymodule into a flexdashboard, the plots are not rendered.

The example below tries to translate the Shiny example from the help for use in a flexdashboard, but although it displays and reads the data (it displays the column names and these change when selecting the "cars" data), it does not update the chart menu neither does it render the plot.

How can I make the plots render when using the esquisse Shiny module?

---
title: "Quick demo for Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---


   
Test
=====================================     
```{r}


library(esquisse)
# shiny inputs defined here
radioButtons(
    inputId = "data", 
    label = "Data to use:", 
    choices = c("iris", "mtcars"))

checkboxGroupInput(
    inputId = "aes", 
    label = "Aesthetics to use:", 
    choices = c(
      "fill", "color", "size", "shape", 
      "weight", "group", "facet", "facet_row", "facet_col"
    ),
    selected = c("fill", "color", "size", "facet"))

  esquisse_ui(
    id = "esquisse", 
    header = FALSE, # dont display gadget title
    container = esquisseContainer(height = "700px"))
  
  
  data_rv <- reactiveValues(data = iris, name = "iris")
  
  observeEvent(input$data, {
    if (input$data == "iris") {
      data_rv$data <- iris
      data_rv$name <- "iris"
    } else {
      data_rv$data <- mtcars
      data_rv$name <- "mtcars"
    }
  })
  
  esquisse_server(
    id = "esquisse", 
    data_rv = data_rv, 
    default_aes = reactive(input$aes)
  )
 
  
```

标签: rggplot2flexdashboardshinymodules

解决方案


我已将esquisse_ui()功能放入renderUI()功能中,并且效果很好。试试看。

完整示例:

```{r}
esqSData <- reactiveValues(data = mydata, name = "My Data")

esquisse_server(
  id = "esquisse",
  data_rv = esqSData,
  import_from = c("env", "file", "copypaste", "googlesheets") )

renderUI(
  esquisse_ui(
    id = "esquisse",
    header = TRUE,
    container = esquisseContainer(),
    controls = c("labs", "parameters", "appearance", "filters", "code"),
    insert_code = FALSE
    )
)
```

推荐阅读