0

I'm trying to divide a big shiny UI interface into separate files and then call them using source() function.

Everything work smoothly except that the source() function add a "TRUE" to my UI.

I tried verbose and echo arguments with no success.

code looks like this:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
      source("side_panel.R")
      ),

      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

and side_panel.R is:

sliderInput("bins",
            "Number of bins:",
            min = 1,
            max = 50,
            value = 30)
Mehdi Zare
  • 1,221
  • 1
  • 16
  • 32
  • 1
    What's your question/problem? – pogibas Sep 14 '18 at 18:15
  • Is that the entire `side_panel.R` file? And what do you mean by "add a "TRUE" to my UI."? Does you mean it adds the word "TRUE" in text? Does it also add the `sliderInput`? – divibisan Sep 14 '18 at 18:25
  • @Dason3 It's there " source("side_panel.R")" – Mehdi Zare Sep 14 '18 at 18:39
  • @divibisan Yes. you can run the code. It add the word "TRUE" after loading the code from the "side_panel.R" file – Mehdi Zare Sep 14 '18 at 18:40
  • @PoGibas I don't want to have the word "TRUE". Is there any other function to load the code with no other visible output? – Mehdi Zare Sep 14 '18 at 18:41
  • `source()` isn't meant to return a value.It sounds like you probably want to use shiny modules. See this link for modularizing your shiny code: https://shiny.rstudio.com/articles/modules.html – MrFlick Sep 14 '18 at 18:44

0 Answers0