Create URL hyperlink in R Shiny?
By using paste
, you're treating the url
as a string. The function you want to use here is tagList
:
runApp(
list(ui = fluidPage(
uiOutput("tab")
),
server = function(input, output, session){
url <- a("Google Homepage", href="https://www.google.com/")
output$tab <- renderUI({
tagList("URL link:", url)
})
})
)
Textoutput as hyperlink in R shiny
This might work but I can't test without your file
library(shiny)
info_360 <- read.csv('data/360_photos.csv')
ui <-
fluidRow(
box(
title = "Key Facts",
closable = FALSE,
width = 9,
status = "primary",
solidHeader = FALSE,
collapsible = TRUE,
uiOutput("keyfacts"))
server <- function(input, output,session) {
Keyfactstext <- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText)%>%
pull(Key_facts)
**#this contains a text that includes a website link, I need only the link to appear as a hyperlink?????????????????**
}
})
output$keyfacts<- renderUI({
tagList$a(href = Keyfactstext(), "Click me")})
}
shinyApp(ui = ui, server = server)
How to create hyperlink on element of R Shiny application?
Please check the following approach:
navbarPage
needs an id to select a tab programaticallysuspendWhenHidden = FALSE
for yourrenderUI
call to have theselectizeInput
ready before the first link is clickedbindAll
shiny tags to receive the link-click viaobserveEvent
- Please see this related answer from Joe Cheng.updateNavbarPage
andupdateSelectizeInput
library(shiny)
library(DT)
library(data.table)
ui <- fluidPage(
navbarPage('TEST', id = "navbarID",
tabPanel("Table",
fluidPage(
fluidRow(dataTableOutput("dt_table")))),
tabPanel("Letters",
fluidPage(
fluidRow(uiOutput("uo_selector"))))
)
)
server <- function(input, output, session) {
output$uo_selector <- renderUI({
selectizeInput(
'si_letters', 'Letters',
choices = c("A", "B", "C"),
multiple = FALSE, selected = "A")
})
outputOptions(output, "uo_selector", suspendWhenHidden = FALSE)
df_table <- reactive({
data.table(
letters = lapply(seq_len(3), function(i){as.character(actionLink(inputId = paste0("link_", LETTERS[i]), label = LETTERS[i]))}),
numbers = c(1, 2, 3)
)
})
lapply(seq_len(nrow(isolate(df_table()))), function(i){
observeEvent(input[[paste0("link_", LETTERS[i])]], {
updateNavbarPage(inputId = "navbarID", selected = 'Letters')
updateSelectizeInput(inputId = "si_letters", selected = LETTERS[i])
})
})
output$dt_table <- renderDataTable({
DT::datatable(
df_table(), escape = FALSE,
options = list(pageLength = 5,
preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
)
)
})
}
# Run the application
shinyApp(ui, server)
Is there a way to place a hyperlink inside a textInput with Shiny R
As @Stéphanie mentioned, this is not possible.
Because you include the a tag as value of an input element. If you look at the HTML you will see:
<input id="test" type="text" class="form-control shiny-bound-input" value="<a href="https://www.google.com/">Google Homepage</a>">
So if you just want a clickable link you dont need a textInput
.
Just put the a tag
in the fluidPage
:
test <- a("Google Homepage", href="https://www.google.com/")
runApp(
list(ui = fluidPage(
test
),
server = function(input, output, session){
})
)
Hyperlink to cell value in R shiny (with many columns)
@Stéphane Laurent will know better than me, but you could try this as your JS renderer. You can check if data
is NULL if your if
statement, and probably should include data
in your hyperlink reference instead of "row". Try this out and and let me know if this helps.
render <- c(
"function(data, type, row){",
" if(type === 'display' && data){",
" var a = '<a href=\"http://www.swisslipids.org/#/search/' + data + '\">' + data + '</a>';",
" return a;",
" } else {",
" return data;",
" }",
"}"
)
Edit: If you have "Cer(d18:1_16:0)+OH" as an entry in a cell, but want to use "Cer(d18:1/16:0)" in your link, you could use the replace
function and chain them for multiple replacements. In this case use /g for global modifier. You can adjust the regex for your particular needs.
render <- c(
"function(data, type, row){",
" if(type === 'display' && data){",
" var newstr = data.replace(/_/g, '/').replace(/\\).*/g, ')');",
" var a = '<a href=\"http://www.swisslipids.org/#/search/' + newstr + '\">' + data + '</a>';",
" return a;",
" } else {",
" return data;",
" }",
"}"
)
how to open a link in shiny
I guess you just wanted a resizable browser tab popup, for this you edit the JS
and add resizable
argument:
library(shiny)
ui <- fluidPage(shiny::fluidRow(shiny::actionButton(inputId='ab1',
label="click here", value = "Open popup",onclick ="window.open('http://google.com','_blank','resizable,height=260,width=370')")))
server <- function(input, output) {}
shinyApp(ui, server)
Related Topics
Warning in Install.Packages: Unable to Move Temporary Installation
Output a Good-Looking Matrix Using Rendertable()
How to Make a Timeseries Boxplot in R
How to Find Common Rows Between Two Dataframe in R
Extract First Word from a Column and Insert into New Column
Assign Names to Data Frame with As.Data.Frame Function
Display a Summary Line Per Facet Rather Than Overall
R, Find Duplicated Rows , Regardless of Order
Filtering Rows in R Unexpectedly Removes Nas When Using Subset or Dplyr::Filter
How to Merge Two Data Frames on Common Columns in R with Sum of Others
R Fast Single Item Lookup from List VS Data.Table VS Hash
How to Format Data for Plotly Sunburst Diagram
Dplyr Group by Colnames Described as Vector of Strings
Canonical Tidyverse Method to Update Some Values of a Vector from a Look-Up Table
How to Turn Gpclibpermit() to True