我想通过将代码的各个部分移动到单独的文件中来对我闪亮的应用程序代码进行模块化。然后,我使用对source
函数的调用来包含文件的内容:source("./www/some_code.R", local = TRUE)
除了效果不佳外,它效果很好:TRUE
一词被添加到插入内容的正下方。
您能帮助我理解为什么会发生这种情况以及如何删除不需要的文本吗?
例如,
创建app.R
:
#
# 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("./www/slider.R", local = TRUE)
),
# 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)
,在www
文件夹中,slider.R
:
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
答案 0 :(得分:0)
当我发布此消息时,我看到了指向该问题的链接,它回答了以下问题:displaying TRUE when shiny files are split into different folders
我以为我做了研究...我应该删除整个线程吗?