3

My goal is to include an action link (that displays a help text) into the label of a selectInput button.

library(shiny)

ui <- fluidPage(
  br(),
  selectInput(
    inputId = "some_id", 
    label = "Please choose A or B (get help)",
    choices = c("choice A", "choice B"),
    selected = "choice A",
    selectize = F
  ),
  actionLink(inputId = "action_link", label = "get help")
) # fluidPage

server <- function(input, output) {}

shinyApp(ui, server)

enter image description here

I guess the solution is to use label = HTML(...), but I do not know how to rewrite the action link in plain html.

Joe
  • 1,628
  • 3
  • 25
  • 39

2 Answers2

4
  selectInput(
    inputId = "some_id", 
    label = HTML("Please choose A or B", 
                 as.character(actionLink(inputId = 'action_link', label = 'get help'))),
    choices = c("choice A", "choice B"),
    selected = "choice A",
    selectize = F
  )
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • how would you do this while using `updateSelectInput`, I tried using the same `HTML` block, but it just prints the `HTML` code and not the intended `actionLink` – road_to_quantdom Apr 03 '19 at 08:53
4

You can also use tags such as a and p

library(shiny)

ui <- fluidPage(
  br(),
  selectInput(
    inputId = "some_id", 
    label = p("Please choose A or B ",a("get help", href = "https://www.google.com/", target = "_blank")),
    choices = c("choice A", "choice B"),
    selected = "choice A",
    selectize = F
  )
) # fluidPage

server <- function(input, output) {}

shinyApp(ui, server)

enter image description here

Pork Chop
  • 28,528
  • 5
  • 63
  • 77