rCharts 突出显示 Shiny 的图表不起作用

标签 r highcharts shiny rcharts

使用现有问题的答案作为可重现代码的基础 here

我收到以下错误,不确定为什么它不起作用...这似乎是渲染时的一个普遍问题 hPlot在 shiny 中键入图表,因为我不断收到相同的错误

Listening on http://127.0.0.1:7537
Error in normalizePath(directoryPath, mustWork = TRUE) : 
  path[1]="": No such file or directory


Error in normalizePath(directoryPath, mustWork = TRUE) : 
  path[1]="": No such file or directory
> traceback()
21: normalizePath(directoryPath, mustWork = TRUE)
20: addResourcePath(LIB$name, LIB$url)
19: singleton(addResourcePath(LIB$name, LIB$url))
18: withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage"))
17: suppressMessages(singleton(addResourcePath(LIB$name, LIB$url)))
16: showOutput("myChart", "Highcharts")
15: tag("div", list(...))
14: tags$div(...)
13: div(class = paste0("col-sm-", width), ...)
12: mainPanel(showOutput("myChart", "Highcharts"))
11: tag("div", list(...))
10: tags$div(...)
9: div(class = "row", sidebarPanel, mainPanel)
8: tag("div", list(...))
7: tags$div(...)
6: div(class = "container-fluid", div(class = "row", headerPanel), 
       div(class = "row", sidebarPanel, mainPanel))
5: tagList(if (!is.null(title)) tags$head(tags$title(title)), if (!is.null(theme)) {
  tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                      href = theme))
}, list(...))
4: attachDependencies(tagList(if (!is.null(title)) tags$head(tags$title(title)), 
                              if (!is.null(theme)) {
                                tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                                                    href = theme))
                              }, list(...)), importBootstrap())
3: bootstrapPage(div(class = "container-fluid", div(class = "row", 
                                                    headerPanel), div(class = "row", sidebarPanel, mainPanel)))
2: pageWithSidebar(headerPanel("rCharts: Highcharts"), sidebarPanel(selectInput(inputId = "x", 
                                                                                label = "Choose X", choices = c("SepalLength", "SepalWidth", 
                                                                                                                "PetalLength", "PetalWidth"), selected = "SepalLength")), 
                   mainPanel(showOutput("myChart", "Highcharts")))
1: runApp(list(ui = pageWithSidebar(headerPanel("rCharts: Highcharts"), 
                                    sidebarPanel(selectInput(inputId = "x", label = "Choose X", 
                                                             choices = c("SepalLength", "SepalWidth", "PetalLength", 
                                                                         "PetalWidth"), selected = "SepalLength")), mainPanel(showOutput("myChart", 
                                                                                                                                         "Highcharts"))), server = function(input, output) {
                                                                                                                                           output$myChart <- renderChart2({
                                                                                                                                             h1 <- Highcharts$new()
                                                                                                                                             h1$chart(type = "spline")
                                                                                                                                             h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
                                                                                                                                             h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
                                                                                                                                             h1$legend(symbolWidth = 80)
                                                                                                                                             return(h1)
                                                                                                                                           })
                                                                                                                                         }))

下面是我在 rCharts 中升级后的 sessionInfo...这导致了同样的错误...另请注意,在 RStudio 的查看器中查看时,突出显示图表在本地工作,但在使用 showOutput 时不 Shiny 功能

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: powerpc64le-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_0.11.1  rCharts_0.4.5

loaded via a namespace (and not attached):
 [1] codetools_0.2-8 digest_0.6.8    grid_3.1.1      htmltools_0.2.6
 [5] httpuv_1.3.2    lattice_0.20-29 mime_0.3        nabor_0.4.4    
 [9] plyr_1.8.1      R6_2.0.1        Rcpp_0.11.5     RJSONIO_1.3-0  
[13] tools_3.1.1     whisker_0.3-2   xtable_1.7-4    yaml_2.1.13   

最佳答案

showOutput() 中将 "Highcharts" 更改为 "highcharts" 为我修复了它(使用 rCharts 版本 0.4.5):

require(rCharts)
require(shiny)
runApp(list(
  ui =  pageWithSidebar(
    headerPanel("rCharts: Highcharts"),
    sidebarPanel(selectInput(
      inputId = "x",
      label = "Choose X",
      choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
      selected = "SepalLength"
    )),
    mainPanel(showOutput("myChart", "highcharts"))
  ),
  server = function(input, output){
    output$myChart <- renderChart2({
      h1 <- Highcharts$new()
      h1$chart(type = "spline")
      h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
      h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
      h1$legend(symbolWidth = 80)
      return(h1)
    })
  }
))

关于rCharts 突出显示 Shiny 的图表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30335630/

相关文章:

r - 是否可以获得转换后的绘图数据? (例如点图中点的坐标、密度曲线)

r - 如何在 r 中的 for 循环中运行协方差

javascript - 在调整大小和放大图表时隐藏 Highcharts 标签

r - Shiny 应用程序无法读取包 : The application failed to start (exited with code 1)

r - 表或数据框上的复选框

r - 按另一个 d.frame R 的列对 d.frame 进行排序

r - install.packages 错误 : Troubleshooting local repo usage

r - 使用 bslib 的可折叠侧边栏无需额外的 JS?

javascript - 如何在特定位置绘制 SVG 形状(取决于 xAxis)

javascript - 在 Highcharts 上绘制自定义线条