运行闪亮的应用程序时访问/使用R控制台 [英] Access/use R console when running a shiny app

查看:65
本文介绍了运行闪亮的应用程序时访问/使用R控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道运行闪亮的应用程序时是否能够访问R控制台吗? (如果可能的话,在后台运行闪亮的应用程序也会有所帮助)

Does anybody know if one is able to access the R console when running a shiny app? (running the shiny application in background would also be helpful, if that's possible)

我需要使用它来处理.GlobalEnv中用于闪亮应用程序的对象,并且使用命令行完成。

I need this for manipulating objects in .GlobalEnv which are used in the shiny application and this has to be done using the command line.

启动应用程序时,控制台很忙。可以从应用程序内部访问控制台吗?

When starting the app the console is buzy. Is there a possibility to access the console from within the application?

预先感谢!

推荐答案

R(且发亮)运行单线程。闪亮的应用程序使用此线程,因此无论何时运行该应用程序,您都无法与R进行交互。如果要在闪亮的会话中运行交互式命令,则需要在应用程序中放入 browser(),如@ eric-canton所述。

R (and shiny) run single-threaded. This thread is used by the shiny application so you cannot interact with R whenever the app is running. If you want to run interactive commands during a shiny session you need to put a browser() inside your application like mentioned by @eric-canton.

一个非常简单的应用程序可能看起来像这样

A very simple application could look like this

library(shiny)

d <- data.frame(1:10, 1:10)

ui <-  fluidPage(
  actionButton("browser", "Trigger browser()"),
  actionButton("reload", "Reload Plot"),
  plotOutput("plot")
)


server <- function(input, output, session) {
  observeEvent(input$browser, {
    browser()
    1 + 1
  })

  output$plot <- renderPlot({
    input$reload
    plot(d)
  })
}

shinyApp(server = server, ui = ui)

对代码的一些评论


  • 我在 browser()命令后放置 1 +1 browser(),因为根据我的经验,最后一个参数倾向于意外终止交互式终端

  • 您需要一些闪亮的事件来触发重绘图的原因,因为 d 不是响应值

  • 如果您在控制台上,则需要为 d ,原因是使用 d 位于您要调用的函数之外:

  • I put 1 + 1 after the browser() command because setting browser() as the last argument tends to stop the interactive terminal unexpectedly in my experience
  • You need some shiny event to trigger the redrawing of the plot, because d is not a reactive value
  • If you are on the console you need to assign a new value to d by using the <<- operator because d lives outside the function you are calling:
Browse[2]> d <<- data.frame(x = 1:200, y = 200:1)



  • 您可以跳出交互式控制台并通过输入 c 并单击Enter

    • You can jump out of interactive console and resume the app by entering c and hitting Enter
    • 这篇关于运行闪亮的应用程序时访问/使用R控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆