This might sound weird question but hear me out.
Let's take a simple shiny app -
library(shiny)
ui <- fluidPage(
textOutput("text1"),
plotOutput('plot1')
)
server <- function(input, output, session) {
output$text1 <- renderText("This is text input")
output$plot1 <- renderPlot(plot(rnorm(10), rnorm(10)))
}
shinyApp(ui, server)
So in this app, we have 1:1 mapping of input and output UI elements. textOutput
with renderText
and plotOutput
with renderPlot
.
Now, what I am trying to do is combine the ui and server part of each element in one function.
text_element <- function(input, output, server) {
textOutput("text1")
output$text1 <- renderText("This is text input")
}
plot_element <- function(input, output, server) {
plotOutput('plot1')
output$plot1 <- renderPlot(plot(rnorm(10), rnorm(10)))
}
I know this doesn't make sense but this is just to give an idea.
My questions are -
- Is this possible? Are there any examples/packages that does this?
- If 1) is possible, how do I use it in shinyapp to make it work like the original app?
- Are there any downsides of this approach?
Thank you for your time and valuable input.