`c3` 包不适用于 shinyApp 中的反应性

问题描述 投票:0回答:0

我正在尝试在 shinyApp 中的

c3
包图形中使用反应对象。

然而,该图不是由服务器生成的。

查看我使用的代码:

library(shiny)

ui <- fluidPage(
  
  column(
    
    width = 12,
    
    actionButton(
      inputId = "dbtn1",
      label = "Click me!"
    ),
    
    sliderInput(
      inputId = "id1",
      label = "Choose 1",
      value = 5,
      min = 1, 
      max = 10, 
      step = 1
    ),
    
    sliderInput(
      inputId = "id2",
      label = "Choose 2",
      value = 5,
      min = 1, 
      max = 10, 
      step = 1
    )
    
  ),
  
  c3::c3Output(outputId = "dsgraph")
  
)

server <- function(input, output, session) {
  
  reac1 <- reactive({
    
    fx <- function(x, y) {
      
      x + y
      
    }
    
    fx(
      x = input$id1,
      y = input$id2
    )
    
  })
  
  output$dsgraph <- c3::renderC3({
    
    req(input$dbtn1)
    
    isolate(expr = q1 <- reac1())
    isolate(expr = q2 <- reac1())
    
    data.frame(Before = q1, After = q2) %>%
      c3::c3() %>%
      c3::c3_donut(title = "Show donut")
  })
  
}

shinyApp(ui, server)

但是,如果我输入绝对值,例如:

  output$dsgraph <- c3::renderC3({
    
    req(input$dbtn1)
    
    data.frame(Before = 20, After = 80) %>%
      c3::c3() %>%
      c3::c3_donut(title = "Show donut")

  }) 

工作正常。

在我看来

actionButton
在第一次按下后失去了点击效果......

r c3.js
© www.soinside.com 2019 - 2024. All rights reserved.