使用以下代码
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)
然而,闪亮的应用程序没有渲染情节。它看起来很空洞。任何建议将不胜感激。
答案 0 :(得分:1)
当使用带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)