Using Source() in Shiny

R Shiny: source command prints TRUE on app

I found the fix here: add a [1] at the end of the source(.) command:

library(shiny)
library(ggplot2)

# Define UI for app that draws a histogram ----
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
source("~/stackoverflow/17150062/sub.R", echo = FALSE, print.eval = FALSE)[1]
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)

server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful$waiting
ggplot(tibble(x), aes(x=x)) + geom_histogram( binwidth = input$bins)
})
}

shinyApp(ui = ui, server = server)

Sample Image

How to use the source() function to launch a R Shiny app

Use function runApp from shiny package to launch app:

shiny::runApp(appDir = "path/to/my/Shiny_app.R")

Using the source command in Rshiny without TRUE evaluation

use source("TestSource.R", local=TRUE)$value

A good explanation is here

R - source()'ing files in Shiny UI Layer

Try source("tmp.R",local = TRUE)$value maybe



Related Topics



Leave a reply



Submit