【问题标题】:RStudio Server + Shiny - [No stack trace available]RStudio Server + Shiny - [没有可用的堆栈跟踪]
【发布时间】:2021-08-17 14:01:06
【问题描述】:

我需要帮助,我正在努力学习闪亮,但我遇到了以下问题:我根本没有收到任何堆栈跟踪。即使我正在复制书中的示例:

https://mastering-shiny.org/action-workflow.html#tracebacks-in-shiny

我书中的闪亮代码只是为了测试堆栈跟踪:

library(shiny)
   
   h <- function(x) x * 2
   
   ui <- fluidPage(
     selectInput("n", "N", 1:10),
     plotOutput("plot")
   )
   server <- function(input, output, session) {
     output$plot <- renderPlot({
       n <- h(input$n)
       plot(head(cars, n))
     }, res = 96)
   }
   shinyApp(ui, server)

我收到的信息是:

Listening on http://127.0.0.1:7840
Warning: Error in *: non-numeric argument to binary operator
  [No stack trace available]

R studio 服务器正在运行:10.4.1.252:8787

我的猜测是与 Shiny 连接的东西正在侦听本地 IP 地址 (127.0.0.1) 并且应用程序正在远程服务器上运行,我需要连接到 VPN 才能连接到该机器(以及 RStudio 服务器)本身)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    对于回溯,只需将traceback() 添加到server.R

    library(shiny)
    
    h <- function(x) x * 2
    
    ui <- fluidPage(
      selectInput("n", "N", 1:10),
      plotOutput("plot")
    )
    server <- function(input, output, session) {
      output$plot <- renderPlot({
        n <- h(input$n)
        plot(head(cars, n))
      }, res = 96)
      traceback()
    }
    shinyApp(ui, server)
    

    ##########################

    13: execCallbacks(timeoutSecs, all, loop$id)
    12: run_now(timeoutMs/1000, all = FALSE)
    11: service(timeout)
    10: serviceApp()
    9: ..stacktracefloor..(serviceApp())
    8: withCallingHandlers(expr, error = doCaptureStack)
    7: domain$wrapSync(expr)
    6: promises::with_promise_domain(createStackTracePromiseDomain(), 
           expr)
    5: captureStackTraces({
           while (!.globals$stopped) {
               ..stacktracefloor..(serviceApp())
           }
       })
    4: ..stacktraceoff..(captureStackTraces({
           while (!.globals$stopped) {
               ..stacktracefloor..(serviceApp())
           }
       }))
    3: runApp(x)
    2: print.shiny.appobj(x)
    1: (function (x, ...) 
       UseMethod("print"))(x)
    Warning: Error in *: non-numeric argument to binary operator
      [No stack trace available]
    

    【讨论】:

    • 不幸的是它没有帮助:(。响应如下。我认为这与监听本地地址(127.0.0.1)和在远程机器上工作的 RStudio 服务器有关我正在通过 VPN 连接。监听 127.0.0.1:3087 没有可用的回溯警告:* 中的错误:二进制运算符的非数字参数 [没有可用的堆栈跟踪]
    【解决方案2】:

    错误已经给你带来了问题:

    selectInput 默认创建一个字符类输入(这可能会随着时间而改变)

    有两种解决方法:

    1. 使用 as.numeric()
    2. 使用 numericInput()
    library(shiny)
    
    h <- function(x) x * 2
    
    ui <- fluidPage(
      selectInput("n", "N", 1:10),
      numericInput("n2", "Num input",1,min=1,max=10, step = 1),  # solution 2
      plotOutput("plot"),
      textOutput("c1"),
      textOutput("c2")
    )
    server <- function(input, output, session) {
      output$plot <- renderPlot({
        n <- h(as.numeric(input$n))  # solution 1
        plot(head(cars, n))
      }, res = 96)
      # explanation:
      output$c1<-renderText({class(input$n)})
      output$c2<-renderText({class(as.numeric(input$n))})
      output$c3<-renderText({class(input$n3)})
    }
    shinyApp(ui, server)
    
    
    

    【讨论】:

    • 嘿。谢谢你,但错误本身不是问题。缺乏追溯是。
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    相关资源
    最近更新 更多