c - 在 shiny 中使用 .C

标签 c r shiny

我正在尝试使用 Shiny 的 robustbase 库中的函数 Qn。此函数调用 C 例程 Qn0,如下所示:

.C(Qn0, as.double(x), n, res = double(1))$res

当我在 R 中运行(比如说)Qn(rnorm(10)) 时,它运行得非常好,但是当我在 shiny 中运行它时,它给出了错误消息

Error in Qn(rnorm(10)) : object 'Qn0' not found

这里是一些示例代码

ui.R

 shinyUI(fluidPage(
    sidebarLayout(
       sidebarPanel(),
       mainPanel(uiOutput("txt"))
   )    
 ))

服务器.R

 library(robustbase)
 shinyServer(function(input, output) {        
      output$txt <- renderText({
          print(getDLLRegisteredRoutines("robustbase"))         
          Qn(rnorm(10))
      })
 })

getDLLRegisteredRoutines("robustbase") 列出了 Qn0,但无论如何我还是得到了错误。我怀疑命名空间有问题,但我一直无法弄清楚它是什么。

沃尔夫冈

最佳答案

这段代码:

library(robustbase)

ui_foo = shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(),
    mainPanel(uiOutput("txt"))
  )    
))

server_foo =  shinyServer(function(input, output) {        
  output$txt <- renderText({
    print(getDLLRegisteredRoutines("robustbase"))         
    Qn(rnorm(10))
  })
})

shinyApp(ui = ui_foo, server = server_foo)

不会为我抛出任何错误。这是我的 sessionInfo:

> sessionInfo()
R version 3.2.5 (2016-04-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
 [1] robustbase_0.92-5    RSQLite_1.0.0        shiny_0.13.2         stringr_1.0.0        zoo_1.7-12          
 [6] chron_2.3-47         ggplot2_2.1.0        RMySQL_0.10.9        DBI_0.4-1            assertthat_0.1      
[11] readr_0.2.2          dplyr_0.4.3          XLConnect_0.2-11     XLConnectJars_0.2-9  readxl_0.1.1        
[16] openxlsx_3.0.0       lubridate_1.5.6.9000

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.4      DEoptimR_1.0-4   plyr_1.8.3.9000  tools_3.2.5      digest_0.6.9     jsonlite_0.9.19 
 [7] gtable_0.2.0     lattice_0.20-33  parallel_3.2.5   rJava_0.9-8      grid_3.2.5       data.table_1.9.6
[13] R6_2.1.2         magrittr_1.5     scales_0.4.0     htmltools_0.3.5  mime_0.4         colorspace_1.2-6
[19] xtable_1.8-2     httpuv_1.3.3     labeling_0.3     stringi_1.0-1    lazyeval_0.1.10  munsell_0.4.3  

关于c - 在 shiny 中使用 .C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37239362/

相关文章:

r - 禁用错误时存储回溯

r - 在 Windows 上托管 Shiny 的应用程序

c - 将字符串写入文件

iOS objective-C : using modulo on a float to get "inches" from Feet

替换为向量

r - 如何通过输入键在 Shiny 中加入两个 react 数据帧?

R shiny - 如何将带有参数的请求 url 发送到 R shiny 并仅获得数据响应?

c - 我的循环队列实现无法正常工作

c - 如何在opencv中找到图像中每个连通分量的边界像素

r - R 中数据帧的 [1], [1,], [,1], [[1]] 有什么区别?