使用在server.R上创建的变量列表填充闪亮的html文本

问题描述 投票:0回答:1

我想使用server.r上生成的list()来填充ui.r中的段落

server.r

shinyServer(function(input, output) {
    output$out <- reactive({
        list(
            a = 'brown',
            b = 'quick',
            c = 'lazy'
        )
    })
})

长子。 [R

library(shiny)
shinyUI(fluidPage(
    p('The ', output$out$a, output$out$b, 'fox jumps over the ', output$out$c, 'dog')
))

我知道代码不正确,你必须使用辅助函数来访问ui.r中的数据,但我只是想说明我的问题。

html r shiny server-side
1个回答
0
投票

也许我不理解你的意图,但看看这个:

library(shiny)

server <- function(input, output) {
  out <- reactive({

    tmp <- list()
    tmp <- list(
      a = 'brown',
      b = 'quick',
      c = 'lazy'
    )

    return(tmp)
  })

  output$a <- function() {
    out()[[1]]
  }

  output$b <- function() {
    out()[[2]]
  }

  output$c <- function() {
    out()[[3]]
    }
}

ui <- shinyUI(fluidPage(
  p('The ', textOutput("a"), textOutput("b"),
    'fox jumps over the ', textOutput("c"), 'dog')
))

shinyApp(ui, server)
© www.soinside.com 2019 - 2024. All rights reserved.