英文:
Using R to add Help Icon beside radioButtons
问题
I'd like to place a helpful icon on the right side of each radio button. When the user hovers over or clicks the helpful icon, I would want text to appear.
The below image is a dropdown menu, but I'm using radio buttons.
NOTE: The radio button options are from a csv file.
Below is my code:
ui <- fluidPage(
fluidRow(
column(5,
wellPanel(
radioButtons('var',
h4('Select a Model Object'),
choices = c(""),
width = '37%'
),
shinyDirButton('directory', 'Select Directory', 'Please Select a Directory')
)
)
)
)
server <- function(input, output, session) {
# Get folder names within the system_models directory
model_names <- read.csv("/Users/fs8/Desktop/Project/MAAT/src/system_models/model_names.csv")
# Update choices for selectInput0
updateRadioButtons(session, "var", choices = setNames(model_names$original_name, model_names$display_name))
}
英文:
I'd like to place a helpful icon on the right side of each radio button. When the user hovers over or clicks the helpful icon, I would want text to appear.
The below image is a dropdown menu, but I'm using radio buttons.
NOTE: The radio button options are from a csv file.
Below is my code:
ui <- fluidPage(
fluidRow(
column(5,
wellPanel(
radioButtons('var',
h4('Select a Model Object'),
choices = c(""),
width = '37%'
),
shinyDirButton('directory', 'Select Directory', 'Please Select a Directory')
)
)
)
)
server <- function(input, output, session) {
# Get folder names within the system_models directory
model_names <- read.csv("/Users/fs8/Desktop/Project/MAAT/src/system_models/model_names.csv")
# Update choices for selectInput0
updateRadioButtons(session, "var", choices = setNames(model_names$original_name, model_names$display_name))
}
答案1
得分: 0
以下是您要翻译的内容:
"I haven't found a way of putting the help icon alongside each button in a set of radio buttons because radioButtons
doesn't give direct access to each individual button. There will be a way, but it might be complex. I wonder if it's worth the effort...
It's easy to put a help icon against each entry in a list of checkboxes, though. You can easily monitor the checkboxes to make sure only one is checked at a given time.
I've provided help content for only one of the widgets, but you should be able to work out what you need to do for the rest.
By the way, your sample code was not reproducible. You'd forgotten to include your library
calls, and, more seriously, we don't have access to your desktop, so we can't populate the radio button list. So I've done something generic.
library(shiny)
library(shinyhelper)
library(magrittr)
ui <- fluidPage(
fluidRow(
column(
5,
wellPanel(
radioButtons(
'var',
h4('Make a choice'),
choices = LETTERS[1:4]
) %>%
helper()
)
),
column(
5,
wellPanel(
h4('Make another choice'),
checkboxInput("checkboxA", "A") %>%
helper(
type = "inline",
title="Help for item A",
content = "Blah, blah, blah!"
),
checkboxInput("checkboxB", "B") %>% helper(),
checkboxInput("checkboxC", "C") %>% helper(),
checkboxInput("checkboxD", "D") %>% helper()
)
)
)
)
server <- function(input, output, session) {
observe_helpers()
}
shinyApp(ui, server)
I've included the magrittr
package because I think piping makes the code more readable. If you don't want to use it, then a sample equivalent is
helper(checkboxInput("checkboxB", "B"))
"
英文:
I haven't found a way of putting the help icon along side each button in a set of radio buttons because radioButtons
doesn't give direct access to each individual button. There will be a way, but it might be complex. I wonder if it's worth the effort...
It's easy to put a help icon against each entry in a list of checkboxes though. You can easily monitor the checkboxes to make sure only one is checked at a given time.
I've provided help content for only one of the widgets, but you should be able to work out what you need to do for the rest.
By the way, your sample code was not reproducible. You'd forgotten to include your library
calls and, more seriously, we don't have access to your desktop, so we can't populate the radio button list. So I've done something generic.
library(shiny)
library(shinyhelper)
library(magrittr)
ui <- fluidPage(
fluidRow(
column(
5,
wellPanel(
radioButtons(
'var',
h4('Make a choice'),
choices = LETTERS[1:4]
) %>%
helper()
)
),
column(
5,
wellPanel(
h4('Make another choice'),
checkboxInput("checkboxA", "A") %>%
helper(
type = "inline",
title="Help for item A",
content = "Blah, blah, blah!"
),
checkboxInput("checkboxB", "B") %>% helper(),
checkboxInput("checkboxC", "C") %>% helper(),
checkboxInput("checkboxD", "D") %>% helper()
)
)
)
)
server <- function(input, output, session) {
observe_helpers()
}
shinyApp(ui, server)
I've included the magrittr
package because I think piping makes the code more readable. If you don't want to use it, then a sample equivalent is
helper(checkboxInput("checkboxB", "B"))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论