how to align checkBoxGroupInput and rendertext OUTPUTS in shiny?

Viewed 175

This is my first time posting for help so I hope I am doing averything by the book. I have been searching for a fix to a minor problem I am having with my shiny app for weeks.

Basically, I have a shiny app that let's the user choose which analysis he would like to be done. Three choices in CheckBoxGroupInput...When I check at least two of them, they are displayed in my output but with an indentation that bugs me a lot. How can I align them ?

library(shiny)


ui <- fluidPage(

  pageWithSidebar(

    headerPanel("Analysis") ,
    sidebarPanel (  titlePanel(title = " Options "),   
                    checkboxGroupInput("Analysis", label = h3("Analysis"), 
                                       choices = list("HM", "Palyno", "Pesticides"),
                                       selected = NULL)),
    mainPanel(("Analysis"),


              verbatimTextOutput("MyAnalysis")   ) ))

server <- function(input, output) {

  output$MyAnalysis <- renderText(paste(" You have chosen : ", input$Analysis,"\n"))
    }
shinyApp(ui, server)

So I expect to have my choices aligned in the output, and they are not...

Analysis
 You have chosen :  HM 
  You have chosen :  Palyno 
  You have chosen :  Pesticides 
1 Answers

Here is a solution using renderUI:

library(shiny)

ui <- fluidPage(pageWithSidebar(
  headerPanel("Analysis") ,
  sidebarPanel (
    titlePanel(title = " Options "),
    checkboxGroupInput(
      "Analysis",
      label = h3("Analysis"),
      choices = list("HM", "Palyno", "Pesticides"),
      selected = NULL
    )
  ),
  mainPanel(("Analysis"),
            uiOutput("MyAnalysis"))
))

server <- function(input, output) {
  output$MyAnalysis <- renderUI(HTML(paste0("You have chosen: ", input$Analysis, br())))
}

shinyApp(ui, server)

Result:

enter image description here

Related