Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show example of using a link within text #126

Open
cjrace opened this issue Feb 7, 2025 · 1 comment
Open

Show example of using a link within text #126

cjrace opened this issue Feb 7, 2025 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@cjrace
Copy link
Contributor

cjrace commented Feb 7, 2025

Is your feature request related to a problem? Please describe.
Related to dfe-analytical-services/dfeshiny#51 we want to add an example of linking to different tabs / page views from within the text on a page. We could also use the same page to show an example of the external_link() function too.

Describe the solution you'd like
An example on one of the tabs where we link to another tab for navigation from some text. We can create a new tab for this and include examples of headings, maybe a notification banner, some warning text, and the external_link() function if we want. I'm happy for this to be flexible / chosen by who implements it, though the key thing is the example of linking from text to another tab / page in the dashboard.

Describe alternatives you've considered
We considered adding an internal_link() function, like what we have for external links, but given the amount of different ways you could do this, and there's not too many people who have examples in their apps that would use this right now, the time to creating a robust function for dfeshiny didn't seem like it was worth the effort (though we can revise if proven wrong!).

Additional context

Example bslib code to do if within a module

# Internal link UI function
InternalLinkUI <- function(id) {
  ns <- shiny::NS(id) # Namespace the module
  actionLink(ns("internal_link"), "LA Level page")
}


# Internal link server function
InternalLinkServer <- function(id,
                               tabset_id,
                               tab_value,
                               parent_session) {
  moduleServer(id, function(input, output, session) {
    observeEvent(input$internal_link, {
      # Switch to the specified tab
      bslib::nav_select(
        id = tabset_id,
        selected = tab_value,
        session = parent_session
      )
    })
  })
}
@cjrace cjrace added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 7, 2025
@cjrace
Copy link
Contributor Author

cjrace commented Feb 7, 2025

Alternative approach can use a more traditional HTML A tag like so (what Jake did for LAIT):

internal_nav_link <- function(id, link_text, target_tab, target_id) {  
    ns <- NS(id) # Namespace the module  
    tags$a(    id = ns("internal_link"),    
    href = "#", # Prevent default anchor behavior    
    `data-target-tab` = target_tab, # Tab to switch to    
    `data-target-id` = target_id, # ID of the section to scroll to    
    link_text  
)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant