动态地将输入添加到闪亮的向量中,可用于创建动态文本报告

dynamically add inputs to vector in shiny which can be used to create dynamic text report

嗨,我正在尝试制作一个闪亮的应用程序,它将:

接受多个输入,用于创建文本报告。

我正在尝试将输入值收集到向量中,然后使用粘贴折叠向量以创建文本文档。

我希望文档能够响应输入。

input$indication 的值永远在前,
接下来是已选择的多项选择输入$部分。

此应用似乎运行不佳。

非常感谢,

library(shiny)


line_double <- paste(rep("═", 54), collapse = "")
line_single <- paste(rep("─", 54), collapse = "")
line_short_dash <- paste(rep("-", 125), collapse = "")
bullet <- "•"
r_arrow <- "→"



ui <- fluidPage(
  
  titlePanel("test app"), 
  
  sidebarLayout(
    
    
    sidebarPanel(
      
      checkboxGroupInput(inputId = "sections", 
                         label = "Select Text Sections", 
                         choices = list(
                           "favorite pets", "favorite colors", "favorite cars"
                         ))
      
    ),
    
    mainPanel(
      
      tabsetPanel(
        
        tabPanel("Inputs",   
                 textAreaInput("indication", 
                               "Tell us about yourself", 
                               width = "600px", 
                               height = "70px", 
                               value = "")
        ),
        
        tabPanel("Report",
                 htmlOutput("text", width = '50px')
        )
      )
      
    )
  )
  
)



server <- function(input, output, session) {
  
  text_df <- reactive({
    
    d <- data.frame(text = c(""))
    
    # the indication must always go in the first spot (top of the report)
    d$text[1] <- paste(line_double,
                       input$indication,
                       line_double,
                       sep = "</br>")
    
    
    for (i in 1:length(input$sections)){
      
      d$text[1+i] <- paste(line_double, 
                           input$sections[i], 
                           line_double, 
                           sep = "</br>")
      
    }
    
    
    return(d)
    
  })
  
  
  
  
  output$text  <- renderUI({
    
    
    HTML(
      paste(
        
        text_df()$text, 
        collapse = "</br></br>"

        
      )
    )
    
    
    
  })
  
}
shinyApp(ui, server)






谁能帮忙

这样的怎么样?

library(shiny)


line_double <- paste(rep("═", 54), collapse = "")
line_single <- paste(rep("─", 54), collapse = "")
line_short_dash <- paste(rep("-", 125), collapse = "")
bullet <- "•"
r_arrow <- "→"



ui <- fluidPage(
  
  titlePanel("test app"), 
  
  sidebarLayout(
    
    
    sidebarPanel(
      
      checkboxGroupInput(inputId = "sections", 
                         label = "Select Text Sections", 
                         choices = list(
                           "favorite pets", "favorite colors", "favorite cars"
                         ))
      
    ),
    
    mainPanel(
      
      tabsetPanel(
        
        tabPanel("Inputs",   
                 textAreaInput("indication", 
                               "Tell us about yourself", 
                               width = "600px", 
                               height = "70px", 
                               value = "")
        ),
        
        tabPanel("Report",
                 htmlOutput("text", width = '50px')
        )
      )
      
    )
  )
  
)



server <- function(input, output, session) {
  
  text_df <- reactive({
    
    d <- data.frame(text = c(""))
    
    # the indication must always go in the first spot (top of the report)
    text_indication <- paste(line_double,
                    input$indication,
                    line_double,
                    sep = "</br>")
    
    text_sections <- paste(line_double, 
                           input$sections, 
                           line_double, 
                           sep = "</br>")
      
    d$text <- paste(text_indication, 
                    text_sections, 
                    collapse = "</br>")
    
    
    return(d)
    
  })
  
  
  
  output$text  <- renderUI({
   
    
    HTML(
      paste(
        
        text_df()$text, 
        collapse = "</br></br>"
        
        
      )
    )
    
    
    
  })
  
}
shinyApp(ui, server)