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)
但是,shiny app 没有渲染剧情。它看起来是空的。如有任何建议,我们将不胜感激。
将 rCharts 包与 r shiny 一起使用时,您需要指定您使用的 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)
使用下面的代码
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)
但是,shiny app 没有渲染剧情。它看起来是空的。如有任何建议,我们将不胜感激。
将 rCharts 包与 r shiny 一起使用时,您需要指定您使用的 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)