r - Is it possible to replicate shiny element across application -
i'm working on simple shiny application consists of multiple panels, the ui.r
structured code below:
shinyui(navbarpage("example", tabpanel("sample analysis", sidebarlayout( sidebarpanel( sliderinput("bins", "number of bins:", min = 1, max = 50, value = 30) ), mainpanel( plotoutput("distplot") ) )), tabpanel("sample analysis 2", sidebarlayout( sidebarpanel( sliderinput("bins", "number of bins (again!)", min = 1, max = 50, value = 30) ), mainpanel( plotoutput("distplot") ) )) ))
each of panel provides access different functionalities aspects of code same. example each of panels may provide access selection mechanism 1 particular object, in case of example above illustrated sliderinput
replicated across 2 panels. i'm interested in exploring whether possible replicate same part of interface x
number of times without need type whole sliderinput
code?
edit
to complicate problem further, within function have reactive component, on lines:
build_eqls_drop_down <- function(){ sidebarpanel(selectinput("selection", h5("selection"), dynamic_vars()), uioutput("dynamic_list_derived_according_to_selection")) }
when encapsulated in function uioutput
-generated element not appear. in addition, happy function take no parameters don't mind ui
elements having same id (in effect i'm trying have 1 element in different places).
you need create function elements want replicate. later call function. can define default parameters there, try have different inputid
on each element avoid conflicts.
here sample code use function create slider default parameters. please note in second tabpanel can replicate x
number of times slider using lapply
(in example 3 times). note can change default parameters.
library(shiny) build_slider <- function(id, label="number of bins:", mxmi=c(1,50), val=30){ sliderinput(id, label, min = mxmi[1], max = mxmi[2], value = val) } runapp(list( ui = shinyui(navbarpage("example", tabpanel("sample analysis", sidebarlayout( sidebarpanel( build_slider("bins_1") ), mainpanel( plotoutput("distplot_1") ) )), tabpanel("sample analysis 2", sidebarlayout( sidebarpanel( lapply(1:3, function(k) { id = paste("bins", k, sep="_") build_slider(id, val = k*10) }) ), mainpanel( plotoutput("distplot_2") ) )) )), server = function(input, output, session) { } ))
you can create function create shiny elements complex want. can create function create complete tappanel
includes number of widgets , plots.
Comments
Post a Comment