【问题标题】:R - source()'ing files in Shiny UI LayerR - Shiny UI 层中的 source()'ing 文件
【发布时间】:2016-05-04 18:35:41
【问题描述】:

我正在尝试将我的 Shiny 应用程序分解为更小的文件,以便通过 git 与同事进行协作变得更加容易。 This question 帮助我弄清楚如何使用source(...,local=T) 将文件中的source() 添加到我的server.r。现在我正在尝试对我的 UI 层做同样的事情。

考虑一下这个玩具闪亮的应用程序:

library(shiny)

ui <- bootstrapPage(
  plotOutput("test"),
  numericInput("n","Number of points",value=100,min=1)
)

server <- function(input, output, session) {
  output$test = renderPlot({
    x = rnorm(input$n)
    y = rnorm(input$n)
    plot(y~x)
  })
}

shinyApp(ui, server)

这个应用程序符合您的预期,一个包含 100 个随机数据点的超宽图表。现在,如果我只想将plotOutput 移动到单独的文件中(真正的用例是将 UI 的整个选项卡移动到单独的文件中)怎么办?我创建了一个名为 tmp.R 的新文件,它有:

column(12,plotOutput("test"),numericInput("n","Number of points",value=100,min=1))

将它包装在column 语句中的原因是因为逗号不能只是闲逛。现在我将我的 UI 更新为:

library(shiny)

ui <- bootstrapPage(
  source("tmp.R",local=T)
)

server <- function(input, output, session) {
  output$test = renderPlot({
    x = rnorm(input$n)
    y = rnorm(input$n)
    plot(y~x)
  })
}

shinyApp(ui, server)

现在,“TRUE”这个词只是挂在页面底部。

如何消除这个词的出现?为什么会在那里?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    试试source("tmp.R",local = TRUE)$value也许

    【讨论】:

    猜你喜欢
    • 2021-09-04
    • 2018-06-24
    • 2014-03-18
    • 1970-01-01
    • 2014-02-03
    • 2021-06-12
    • 2017-08-06
    • 2021-03-04
    相关资源
    最近更新 更多