R - source()'ing files in Shiny UI Layer -
i'm trying take shiny apps , break them smaller files make collaborating via git coworkers easier. this question helped me figure out how source() in files server.r using source(...,local=t). i'm trying same thing ui layer.
consider toy shiny app:
library(shiny) ui <- bootstrappage( plotoutput("test"), numericinput("n","number of points",value=100,min=1) ) server <- function(input, output, session) { output$test = renderplot({ x = rnorm(input$n) y = rnorm(input$n) plot(y~x) }) } shinyapp(ui, server) this app expect, 1 overly-wide graph of 100 random data points. now, if want move plotoutput separate file (the real use case in moving whole tabs of ui separate files). make new file called tmp.r , has:
column(12,plotoutput("test"),numericinput("n","number of points",value=100,min=1)) the reason wrapping in column statement because comma's can't hanging out. update ui to:
library(shiny) ui <- bootstrappage( source("tmp.r",local=t) ) server <- function(input, output, session) { output$test = renderplot({ x = rnorm(input$n) y = rnorm(input$n) plot(y~x) }) } shinyapp(ui, server) now, word "true" hanging out @ bottom of page.
how eliminate word showing up? why there?
try source("tmp.r",local = true)$value maybe
Comments
Post a Comment