簡體   English   中英

rCharts:情節在RStudio中正常工作但在閃亮的應用程序中是空的

[英]rCharts: plot is working fine in RStudio but empty in shiny app

使用下面的代碼

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閃亮的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM