Open CedricMidoux opened 4 years ago
There are a couple different ways to currently approach this problem. The most straight-forward would be to duplicate code in each case (just make sure to that you're always returning a metaExpr()
:
output$plot <- metaRender2(renderPlot, {
if (input$bins<=30) {
metaExpr(ggplot(faithful, aes_string(..(input$column))) + geom_histogram(bins = ..(input$bins)) + theme_dark())
} else {
metaExpr(ggplot(faithful, aes_string(..(input$column))) + geom_histogram(bins = ..(input$bins)) + theme_bw())
}
})
Clearly that's not ideal if there's lots of code that needs duplicating. A more sophisticated approach that avoids duplication might be through clever use of quote()
and eval()
:
output$plot <- metaRender2(renderPlot, {
my_theme <- if (input$bins<=30) quote(theme_dark()) else quote(theme_bw())
metaExpr({
p <- ggplot(faithful, aes_string(..(input$column)))
p <- p + geom_histogram(bins = ..(input$bins))
p + eval(..(my_theme))
})
})
This generates valid code, but it's also not ideal in that it generates code that has an unnecessary eval()
in it (e.g., p + eval(theme_dark())
).
I don't immediately see an approach that both avoids duplication and generates "perfectly human-like" code...maybe @jcheng5 can think of a better alternative?
Hello, Do you have a new approach for this problem? Thank you in advance
Hello and thank you for your package.
In this example, what is the correct way to write the condition inside
metaRender
for a better display with theShow code
button.Here, the
Show code
button show :I would like it to simply display:
Many thanks in advance for your support!