rCharts 不会在 Shiny 的应用程序中渲染绘图

标签 r plot shiny rcharts

我正在使用以下简单的 Shiny 应用程序代码片段在主面板中绘制输出。但它并没有按预期渲染情节。它在浏览器中没有显示任何内容。但是当我只运行 mPlot 部分时,它会在 RStudio 中正确显示所有交互的绘图。

ui.R
library(shiny)
library(rCharts)

ui<-fluidPage(
  headerPanel("Economics data with rCharts"),
  mainPanel(
    showOutput("myChart","polycharts")
  )
)

server.R
library(shiny)
library(rCharts)
require(datasets)

server<-function(input,output){
  output$myChart<-renderChart({
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
                data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    return(m1)
  })

}

最佳答案

嗨,您使用了错误的 JS 库,它是 morris,而不是 polycharts,请尝试:

# ui.R
library(shiny)
library(rCharts)

ui<-fluidPage(
  headerPanel("Economics data with rCharts"),
  mainPanel(
    showOutput("myChart","morris")
  )
)

# server.R
library(shiny)
library(rCharts)
require(datasets)

server<-function(input,output){
  output$myChart<-renderChart2({
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
                data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    return(m1)
  })

}

shinyApp(ui = ui, server = server)

关于rCharts 不会在 Shiny 的应用程序中渲染绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30920084/

相关文章:

Python 箭袋角度问题 : What is the difference between angles ="uv" and angles ="xy"

r - 绘制 xts 对象 : 'x' must be a time-series object 时出错

r - 使用 Shiny 的文本输入和 dplyr 来过滤数据框中的行

r - 仅当用户查看输出时才进行 Shiny 计算

r - 我如何写 "*value* *plus-minus sign* *value* ",连同文本,以及 ggplot2,R 的注释?

arrays - 如何在 R 中将数组转换为 data.table 并返回?

r - ggplot基于两种不同条件的映射填充

html - 在 R markdown 中嵌入现有的 HTML

ios - 核心图中的两个图可以同时起作用

r - 在 R Shiny 中更改 sliderInput 上的刻度线标签