Reputation: 556
I am trying to link a website to the word "FAQ" which is embedded in a caption. I am trying to lead users to a new webpage when users hit on FAQ.
Here is my code.
Please see "caption = ("Note: See FAQ for more information on difficulties indicators."),"
Diff_plot <- reactive({
ggplot(Diff_data(), aes(x =Difficulty_Type, y = Frequency_Difficulties)) + geom_bar(stat =
"identity",
position = "stack",
fill = "#B61E2E") +
geom_text(
aes(label = Percentage),
vjust = 1,
colour = "white",
position = position_dodge(width=0.9),
fontface = "bold",
size=5,
# angle = 90,
hjust = 0.5
) +
labs(
x = "",
y = "Frequecny",
caption = ("Note: See FAQ for more information on difficulties indicators."),
face = "bold"
) +
theme_bw() + scale_y_continuous(labels = scales::comma) +
theme(plot.title = element_text(
hjust = 0.5,
size = 15,
colour = "Black",
face = "bold"
),
plot.caption = element_text(hjust = 0, color = "black", face = "bold", size=12.5),
axis.text=(blue.bold.12.text), axis.title=blue.bold.14.text, axis.text.x = element_text(angle = -75, vjust = 0, hjust=0)) +
ggtitle(
paste(
"Population by Type of Difficulty in",
input$county_Diff,
"for",
input$sex_diff,
"(",
input$Age_Group_Diff,
")"
)
)
})
Upvotes: 1
Views: 298
Reputation: 393
This is not doable I believe - ggplot
creates an image which is then rendered in your shiny app, and the caption is part of the image rather than separate HTML surrounding it. If you run your app and inspect the source HTML you'll see the <img>
tags where the plot is.
So your best bet is just to pretend you have a caption, and instead use a different piece of UI in your shiny app - something like:
ui <- fluidPage(
plotOutput(outputId = "diff_plot"),
div(tags$p("See the", a("FAQ", href = "...", target = "_blank"), "for more info"),
style = "text-align: right;")
)
server <- function(input, output) {
Diff_plot <- reactive({ ... })
output$diff_plot <- renderPlot({ Diff_plot() })
}
Note the target = "_blank"
necessary if you want the link to open in a new tab, rather than redirect the current page.
Upvotes: 2