【问题标题】:rCharts: plot is working fine in RStudio but empty in shiny apprCharts:绘图在 RStudio 中运行良好,但在闪亮的应用程序中为空
【发布时间】:2016-04-18 03:56:36
【问题描述】:

使用下面的代码

library(shiny)
library(rCharts)    
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
n1 <- nPlot(Freq ~ Hair, 
            group = "Eye", 
            data = hair_eye_male, 
            type = 'multiBarChart')
n1

我在 RStudio 中得到了这个情节

我想为这个情节创建一个闪亮的应用程序。我使用下面的代码创建了应用程序

library(shiny)
library(rCharts)
ui <- fluidPage(
  mainPanel(uiOutput("tb")))
server <- function(input,output){

  output$hair_eye_male <- renderChart({

    hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
    n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
                type = 'multiBarChart')
    return(n1) 
  })
  output$tb <- renderUI({
    tabsetPanel(tabPanel("First plot", 
                         showOutput("hair_eye_male")))
  })
}
shinyApp(ui = ui, server = server)

但是,闪亮的应用程序没有渲染情节。它看起来是空的。任何建议将不胜感激。

【问题讨论】:

    标签: r shiny rcharts


    【解决方案1】:

    当使用带有 r shiny 的 rCharts 包时,您需要指定您使用的 javascript 库。

    通过将行 n1$addParams(dom = 'hair_eye_male') 添加到 renderChart() 并指定您在 showOutput() 中使用的库,代码将起作用。

    library(shiny)
    library(ggplot2)
    library(rCharts)
    
    ui <- fluidPage(
      mainPanel(uiOutput("tb")))
    server <- function(input,output){
    
      output$hair_eye_male <- renderChart({
    
        hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
        n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
                    type = 'multiBarChart')
        n1$addParams(dom = 'hair_eye_male') 
        return(n1) 
      })
      output$tb <- renderUI({
        tabsetPanel(tabPanel("First plot", 
                             showOutput("hair_eye_male", lib ="nvd3")))
      })
    }
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 感谢您的时间和帮助。我使用您的代码出现此错误错误:未使用的参数(lib =“nvd3”)。
    • @aelwan:我使用命令安装了 rCharts:require(devtools) install_github('ramnathv/rCharts')
    猜你喜欢
    • 2015-10-18
    • 2017-11-16
    • 2015-09-04
    • 2017-06-08
    • 2013-07-08
    • 2018-05-21
    • 2021-08-31
    • 1970-01-01
    • 2020-03-05
    相关资源
    最近更新 更多