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

How to use this package in modules #61

Open
Sixing-r opened this issue Oct 14, 2019 · 1 comment
Open

How to use this package in modules #61

Sixing-r opened this issue Oct 14, 2019 · 1 comment

Comments

@Sixing-r
Copy link

Sixing-r commented Oct 14, 2019

Hi Xiaodong,

I try to use this package to display a pie chart in my shiny app including modules, but there is no error and no plot shown.

ui.R

library(shiny)
library(ECharts2Shiny)

fluidPage(
  h1("Test shiny app"),
  sidebarLayout(
    sidebarPanel(
      id = "User_input",
      h1(
        textOutput("edit_inv_title"), 
        class = "text-center"
      ),
      input_ui("input")
    ),
    mainPanel(
      graph_ui("graph")
    )
  )
)

server.R

function(input, output, session){
  
  input_list <- callModule(input_module, "input")
  
  observeEvent(input_list(),{
    callModule(graph_module, "graph", input_list = input_list)
  })
}

global.R

source("modules/graph.R")
source("modules/input.R")

input.R

input_ui <- function(id){

  ns <- NS(id)
  
  tagList(
    selectInput(
      ns("select_box"),
      "Choose what content you wanna check",
      choices = c("A",
                  "B",
                  "C",
                  "D",
                  "E"))
  )
}

input_module <- function(input, output, session){
  
  input_list <- reactive({
    list("select" = input$select_box
    )
  })
  return(input_list)
}

graph.R

library(ECharts2Shiny)

graph_ui <- function(id){
  
  ns <- NS(id)
  loadEChartsLibrary()
  
  tagList(
    tags$div(id="test", style="width:50%;height:400px;"),
    deliverChart(div_id = ns("pie_chart"),
                 running_in_shiny = T)
  )
  
}

graph_module <- function(input, output, session, input_list = NULL){
  
  p1 <- reactive({
    
    if(input_list()[["select"]] == "A"){
      
     dat <- data.frame(
       name = c("A", "B", "C", "D"),
       value = c(10,20,30,40)
     )
      option_list <- list(
        "data" = dat
        )
    }
  })
  

  observeEvent(p1()$data, {renderPieChart(
    div_id = 'pie_chart',
    data = p1()$data
  )})
}
@XD-DENG
Copy link
Owner

XD-DENG commented Oct 16, 2019

Hi @Sixing-r , thanks a lot for sharing the issue.

I have been away from R-related projects for quite a while, and may not have enough time to look into this issue you kindly shared. Sorry for it.

I would be more than happy if you can help dive deeper and check potential root-cause. Please share with me if you do find anything. Thanks a lot, and apologize again.

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