r - In RMarkdown and Shiny, how to wrap inputPanel and renderPlot in a unique call -
let's @ code dynamic report, it's default template strip minimum:
--- output: html_document runtime: shiny --- ```{r} inputpanel(selectinput("n_breaks", label = "number of bins:",choices = c(10, 20, 35, 50), selected = 20)) renderplot({hist(faithful$eruptions, probability = true, breaks = as.numeric(input$n_breaks))}) ``` i define function f1 can run instead , have same output :
--- output: html_document runtime: shiny --- ```{r} f1() ``` is possible ?
the solution in code chunk option.
here 1 way make work example (though in practice it'll easier feed string directly):
--- output: html_document runtime: shiny --- ```{r} f1 <- function(){ inputpanel(selectinput("n_breaks", label = "number of bins:",choices = c(10, 20, 35, 50), selected = 20)) renderplot({hist(faithful$eruptions, probability = true, breaks = as.numeric(input$n_breaks))}) } ``` ```{r,code = as.character(body(f1))[-1]} ```
Comments
Post a Comment