我试过这个:
output$plot <- renderPlot({
getPlot()
}, width=input$plotX, height=input$plotY) # referring to two numericInput boxes
但我得到这个错误:
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
帮助文本建议我使用函数,并且在这些函数中我可以引用 react 值等。但是做了类似的事情后,我仍然得到同样的错误......
有没有办法让用户根据他们输入应用程序的值来调整绘图的大小?
最佳答案
您可以使用 shiny:::exprToFunction
将 react 值包装到函数中。 .
例如,
output$plot <- renderPlot({
getPlot()
}, width=exprToFunction(input$plotX),
height=exprToFunction(input$plotY)))
应该做的伎俩。
关于r - 在 R Shiny 中动态调整 ggplot2 图形的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25172885/