我正在开发一个捆绑了一组应用的软件包,我希望有一个RStudio addin,允许您根据分类选择应用。这个应用程序是shiny gadget,这是一个闪亮的应用程序的特殊迷你版本。
问题在于:
runApp
,这会给出错误。在小工具服务器功能中,我有以下代码:
observeEvent(input$done,{
theapp <- shinyAppDir("Dir/to/app")
stopApp(theapp)
})
但无济于事。我可以将应用程序作为返回值捕获,但不知何故它不会自动打开。
答案 0 :(得分:4)
您可以通过使用rstudioapi
程序包在关闭应用程序时向R控制台发送命令来解决此问题。然后,服务器功能中的代码变为:
observeEvent(input$done,{
command <- "shinyAppDir('Dir/to/app')"
rstudioapi::sendToConsole(command)
stopApp()
})
一个玩具示例来说明:
library(shiny)
ui2 <- fluidPage(
title = "The Second App",
plotOutput("plot")
)
server2 <- function(input, output, session){
output$plot <- renderPlot(hist(iris$Sepal.Length))
}
library(miniUI)
library(rstudioapi)
theGadget <- function(){
ui <- miniPage(
gadgetTitleBar("Get some app"),
miniContentPanel(
renderText("Click on Done")
)
)
server <- function(input, output, session){
observeEvent(input$done,{
command <- "shinyApp(ui2, server2)"
rstudioapi::sendToConsole(command)
stopApp()
})
}
viewer <- dialogViewer("Example")
runGadget(ui, server, viewer = viewer)
}
theGadget()