我一直在使用showModal(modalDialog(...))
在我的闪亮应用程序中将图表显示为弹出窗口,但是当我将它们放入闪亮模块中时,这些图不会呈现。
简短重现如下:非模块触发模态显示图形,模块触发模态显示为空白。有人有主意吗?模态框本身可以正确显示,模态框的非反应性内容也可以正确显示(例如ModalDialog('some text')
)
library(shiny)
# Module UI
myModuleUI = function(id){
ns = NS(id)
fluidRow(
actionButton(ns('button'), 'Module')
)
}
# Module server
myModule = function(input, output, session){
observeEvent(input$button, {
showModal(
modalDialog(
# This renderPlot does not display
renderPlot(ggplot2::qplot(mtcars$mpg))
)
)
})
}
# App UI
ui = fluidPage(
fluidRow(
actionButton('nonModule', 'Non-module'),
myModuleUI('module')
)
)
# App server
server = function(input, output) {
modalFunc = function() {
return(modalDialog(renderText("Non-Module"),
renderPlot(ggplot2::qplot(mtcars$mpg))))
}
observeEvent(input$nonModule, {
showModal(
modalDialog(
# This renderPlot does display
renderPlot(ggplot2::qplot(mtcars$mpg))
)
)
})
callModule(myModule, 'module')
}
# Run the application
shinyApp(ui = ui, server = server)
会话信息:
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS 10.13.3
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.5
loaded via a namespace (and not attached):
[1] Rcpp_0.12.13 digest_0.6.12 mime_0.5 grid_3.3.2 R6_2.2.2 plyr_1.8.4 xtable_1.8-2
[8] jsonlite_1.5 gtable_0.2.0 scales_0.4.1 ggplot2_2.2.1 rlang_0.1.2 lazyeval_0.2.0 labeling_0.3
[15] tools_3.3.2 munsell_0.4.3 httpuv_1.3.5 yaml_2.1.14 colorspace_1.3-2 htmltools_0.3.6 tibble_1.3.4
Edit
发布此答案后,我向 GitHub 上的shinys问题跟踪系统报告了此行为,并且a fix https://github.com/rstudio/shiny/pull/2010几天后提供。因此,您可以从 GitHub 将闪亮更新到最新版本以使其正常工作。或者,使用我在下面提供的解决方案。
原答案
如果您分配一个单独的output
情节的槽位,两种模式都能正常工作。
myModule = function(input, output, session){
output$plot <- renderPlot({
ggplot2::qplot(mtcars$mpg)
})
observeEvent(input$button, {
showModal(
modalDialog(
# This plot does display
plotOutput(session$ns("plot"))
)
)
})
}
我不确定是什么原因造成的。您是否在其他渲染函数中观察到相同的行为?
我对为什么会发生这种情况的猜测
据我所知使用renderXXX
在 ui 定义中(例如...
论证中modalDialog
)只应该工作在RMarkdown
文件。例如,文档outputArgs
论证中?renderPlot
reads
输出参数当在交互式 R Markdown 文档中使用 renderPlot 时,要传递给对plotOutput 的隐式调用的参数列表。
类似的说法可以在?markRenderFunction
。所以事实是
showModal(modalDialog(renderPlot(...)))
甚至在外面工作RMarkdown
文档是一个未记录的功能,因此不可靠。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)