[英]rCharts: plot is working fine in RStudio but empty in shiny app
Using the code below 使用下面的代码
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
I got this plot in RStudio 我在RStudio得到了这个情节
I want to create a shiny app for this plot. 我想为这个情节创建一个闪亮的应用程序。 I created the app using the code below
我使用下面的代码创建了应用程序
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)
However, shiny app didn't render the plot. 然而,闪亮的应用程序没有渲染情节。 It appeared empty.
它看起来很空洞。 Any suggestions would be appreciated.
任何建议,将不胜感激。
When using rCharts package with r shiny you need to specify which javascript library you are using. 当使用带r闪亮的rCharts包时,您需要指定您正在使用的javascript库。
By adding line n1$addParams(dom = 'hair_eye_male')
to renderChart()
and specifying which library you are using in showOutput()
, code will work. 通过增加线
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.