【问题标题】:creating a list/ vector of text from shiny从闪亮创建文本列表/向量
【发布时间】:2018-06-06 17:01:00
【问题描述】:

我们可以创建一个向量/从闪亮给出的输入列表吗?我想创建一个字符串向量,它存储从闪亮的输入中采取的所有动作。

这里是示例代码,所以只要我们改变输入,输出就会在同一行发生变化。

require(shiny)

runApp(list(ui = pageWithSidebar(
  headerPanel("censusVis"),
  sidebarPanel(
    helpText("Create demographic maps with 
             information from the 2010 US Census."),
    selectInput("var", 
                label = "Choose a variable to display",
                choices = c("Percent White", "Percent Black",
                            "Percent Hispanic", "Percent Asian"),
                selected = "Percent White"),
    sliderInput("range", 
                label = "Range of interest:",
                min = 0, max = 100, value = c(0, 100))
    ),
  mainPanel(htmlOutput("text")
  )
),
server = function(input, output) {
  output$text <- renderUI({
    str1 <- paste("You have selected", input$var)
  })
}
)
)

希望看到动态输出(具体来说可以是 n 个输出...)

[1] You have selected Percent White
[2] You have selected Percent Asian
[3] You have selected Percent Black

【问题讨论】:

  • 那么有没有兴趣看例子的三个文本框。如果是,您可以使用 rendertext post 在 UI 中创建 3 个输入框。
  • 抱歉,如果我不清楚,但我正在寻找动态文本输出,它也可以是 3 或 30。

标签: r shiny


【解决方案1】:

这样的?

require(shiny)

runApp(list(ui = pageWithSidebar(
  headerPanel("censusVis"),
  sidebarPanel(
    helpText("Create demographic maps with 
             information from the 2010 US Census."),
    selectInput("var", 
                label = "Choose a variable to display",
                choices = c("Percent White", "Percent Black",
                            "Percent Hispanic", "Percent Asian"),
                selected = "Percent White"),
    sliderInput("range", 
                label = "Range of interest:",
                min = 0, max = 100, value = c(0, 100))
  ),
  mainPanel(verbatimTextOutput("text")
  )
),
server = function(input, output) {
  val<-reactiveValues()
  val$txt<-""

  observeEvent(input$var,{
    new<-paste("You have selected", input$var)
    val$txt<-paste( val$txt,new,sep='\n')
  })
  output$text <- renderText({
    str1 <- val$txt
  })
}
)
)

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多