Skip to content

expandChain breaks when code contains a parse() statement #81

@daattali

Description

@daattali

Minimal example:

library(shinymeta)
input <- list(title = "paste(5, alpha)")
code <- metaExpr(parse(text = input$title))
expandChain(code)

Results in an error

Error: <text>:1:50: unexpected '<'
1: structure(expression(paste(5, alpha)), srcfile = <
                                                     ^

Example in a shiny app:

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

ui <- fluidPage(
  textInput("text", "text", "paste(text, alpha)"),
  checkboxInput("parse", "Parse axis", FALSE),
  plotOutput("plot"),
  actionButton("code", "Show Code")
)

server <- function(input, output, session) {
  output$plot <- metaRender2(renderPlot, {
    
    xtitle <- if (input$parse) parse(text = input$text) else input$text

    metaExpr({
      ggplot(mtcars, aes(mpg,wt)) +
        geom_point() +
        xlab(..(xtitle))
    })
  })
  
  observeEvent(input$code, {
    code <- expandChain(output$plot())
    displayCodeModal(code)
  })
}

shinyApp(ui, server)

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