Last active
March 11, 2019 23:51
-
-
Save JohnCoene/eb53ca0556601b2121cd3e29f315735a to your computer and use it in GitHub Desktop.
String & expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| string <- "print('from string')" | |
| installExprFunction({print("from expression")}, "expr") | |
| ui <- fluidPage( | |
| verbatimTextOutput("string"), | |
| verbatimTextOutput("expression") | |
| ) | |
| server <- function(input, output, session){ | |
| output$string <- renderPrint({eval(parse(text = string))}) | |
| output$expression <- renderPrint({expr()}) | |
| } | |
| shinyApp(ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| expr <- quote(rnorm(1000)) | |
| plot_ui <- function(id){ | |
| ns <- NS(id) | |
| plotOutput(ns("plot")) | |
| } | |
| plot <- function(input, output, session, expr){ | |
| output$plot <- renderPlot({hist(eval(expr))}) | |
| } | |
| ui <- fluidPage( | |
| plot_ui("mod") | |
| ) | |
| server <- function(input, output, session){ | |
| callModule(plot, "mod", expr = expr) | |
| } | |
| shinyApp(ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| expr <- quote(rnorm(100)) | |
| myFunc <- function(expr){ | |
| ui <- fluidPage( | |
| plotOutput("plot") | |
| ) | |
| server <- function(input, output, session){ | |
| output$plot <- renderPlot({ | |
| hist( | |
| eval(expr) | |
| ) | |
| }) | |
| } | |
| shinyApp(ui, server) | |
| } | |
| myFunc(expr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the wrapper I could do:
I have to see if modules are a cleaner way to do that and what is the impact on user-friendliness