Skip to content

Managing complicated control flow #83

@CedricMidoux

Description

@CedricMidoux

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 the Show code button.

library(shiny)
library(shinymeta)
library(ggplot2)

ui <- fluidPage(
  
  titlePanel("Old Faithful Geyser Data"),
  
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30),
      radioButtons("column",
                   "Select column:",
                   choices = c("eruptions", "waiting"))
    ),
    
    mainPanel(
      outputCodeButton(plotOutput("plot"))
    )
  )
)

server <- function(input, output) {
  
  output$plot <- metaRender(renderPlot, {
    p <- ggplot(faithful, aes_string(..(input$column)))
    p <- p + geom_histogram(bins = ..(input$bins))
    if (..(input$bins<=30)) {
      p <- p + theme_dark()
    } else {
      p <- p + theme_bw()
    }
    p
  })
 
}

shinyApp(ui = ui, server = server)

Here, the Show code button show :

library(ggplot2)
p <- ggplot(faithful, aes_string("eruptions"))
p <- p + geom_histogram(bins = 30L)
if (TRUE) {
  p <- p + theme_dark()
} else {
  p <- p + theme_bw()
}
p

I would like it to simply display:

library(ggplot2)
p <- ggplot(faithful, aes_string("eruptions"))
p <- p + geom_histogram(bins = 30)
p <- p + theme_dark()
p

Many thanks in advance for your support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions