I am trying to add a hyperlink text which should open outlook or gmail (doesnt matter which one) in Shiny
However it opens google.com...why?
library(shiny)
ui <- fluidPage(
box(
"If you have any questions, please contact us at ",
strong(a(href = "mailto:example#email.com", "example#email.com"))
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
I have tried to implement the solution proposed here:
Not following URL Path Protocol
to separate all my plots in different files.
So basically I have radio buttons and based on user choice a different html file is loaded:
else if (input$chap == "4" & input$cat == "2") {
output$uiStub <- renderUI(tagList( # a single-output stub ui basically lets you
fluidPage( # move the ui into the server function
fluidRow(
column(12,
includeHTML("./html/mediapar.html")
)
),
uiOutput("pageStub") # loaded server code should render the
) # rest of the page to this output$
))
}
My problem is that every time a different file refresh (only one part of the page) the focus of page is lost and user has to scroll down again and again to get to the end of page where the choice can be made again and the plot shown.
fluidRow( style = "background-color:#FFFAFA00;",
box(
width = 12,
solidHeader = TRUE,
header = TRUE,
background = NULL,
ui <- uiOutput("uiStub")
)
Is there any workaround for this situation?
Kind Regards
I have used the following code to create an URL in my shiny App to open google on clicking the link
output$Reverse<- renderUI({
tags$a(href="www.google.com", "Search") })
How do I change the font size and color of the word search in the App.
I request someone to help me here.
Just add a style argument to the a-tag using css:
library(shiny)
ui <- fluidPage(
uiOutput("Reverse")
)
server <- function(input, output, session) {
output$Reverse<- renderUI({
tags$a(href="http://www.google.com", "Search", style = "font-size: 200px; color: red;")
})
}
shinyApp(ui, server)
I have a leaflet map in a shiny app. It takes a file from a user and plots that data. It's kind of ugly right now, though. I'd really like to have the fileInput to be overlaid on the leaflet map. In other words, I want the page to be entirely the leaflet map, but with the file input floating above it, similar to the zoom button.
I want the fileInput upload button to to look kind of like the elements of this shiny app. It has logos overlaid on the top left, as well as checkboxes overlaid on the left and a title overlaid on the top right.
Here's a basic (over-simplified) outline of my app:
library(shiny)
library(shinydashboard)
library(leaflet)
shinyApp(
ui <- bootstrapPage(
fileInput("file_in", label = "label"),
tags$style(type="text/css", "html, body {width:100%;height:100%}"),
leafletOutput("myMap", width="100%", height="100%")
),
server = function(input, output) {
my_table <- reactive({
inFile <- input$file_in
if (is.null(inFile))
return(NULL)
myData = read.csv(inFile$datapath)
return(myData)
})
output$myMap = renderLeaflet({
if(is.null(my_table()))
{
return(leaflet()) %>% addTiles()
}
else
{
leaflet(data = my_table()) %>% addTiles()
}
})
}
)
I did this by using absolutePanel(..., fileInput()) in the ui.
I came across this problem when building a Shiny application in R. In the application, an action button is used to trigger a hidden download button. This would allow me to observe the action button event, react to that event, and then trigger the download process.
However, when I set the display attribute of the download button to hidden the href target of the button, which typically targets something like "session/1c47..ef8/download/download_show?w=", was missing.
Below is a smaller Shiny application which reproduces the problem.
shinyApp(
ui = fluidPage(
tags$head(
tags$style(HTML(".hide { display: none; }")),
tags$script(HTML('
Shiny.addCustomMessageHandler("trigger-button", function(message) {
document.getElementById(message.button_id).click();
});
'))
),
div(
class = "disable",
downloadButton("download_shown", "Shown"),
div(
class = "hide",
downloadButton("download_hidden", "Hidden")
)
),
br(),
actionButton("trigger_shown", "I can trigger the visible button!"),
actionButton("trigger_hidden", "I can trigger the hidden button!")
),
server = function(input, output, session) {
output$download_shown <- downloadHandler(
filename = "sample.txt",
content = function(file) {
cat("I'm visible!\n", file = file)
}
)
output$download_hidden <- downloadHandler(
filename = "sample2.txt",
content = function(file) {
cat("I'm hidden!\n", file = file)
}
)
observeEvent(input$trigger_shown, {
session$sendCustomMessage(
"trigger-button",
list(button_id = "download_shown")
)
})
observeEvent(input$trigger_hidden, {
session$sendCustomMessage(
"trigger-button",
list(button_id = "download_hidden")
)
})
}
)
In the application, the two action buttons trigger their corresponding download button. Triggering the visible download button causes a correct download of the file sample.txt. Triggering the hidden download button causes a download of an HTML file, the webpage, instead of the sample2.txt file. Furthermore, if you inspect the HTML generated you can see that the download_hidden download button has an href attribute with no target.
Is there anything in the HTML spec that dictates a hidden element
cannot have an href target? This seems highly unlikely and none of my
searching has turned up any -one or -thing confirming this.
Internally does Shiny ignore elements which are hidden?
In the mean time, does anyone have a suggestion for hiding the button
without using hidden or display: none;?
Thank you in advance.
display:none; causes any element to be not rendered. Therefore, it will not take any space in the document. Therefore, it will not receive any (real) pointer-events.
I would not even count on its ability to receive programmatically triggered pointer events, as I expect at least a few major browsers to interfere, in the name of general browsing safety principles.
If you want your element to be a valid target for user interaction (real or programmatic), I suggest using...
opacity: .01;
...on it. This way it will be rendered. If you don't want it to occupy any space in the content flow, consider applying position:absolute to it.
I have discovered the solution thanks to this issue over on GitHub.
Shiny, by default, suspends objects which are hidden. So, by hiding a downloadButton the corresponding downloadHandler is suspended. I am still unsure how Shiny uses downloadHandler to register a download, but however the process works, it is not triggered if, as I said, the corresponding downloadButton is hidden.
The solution is to use the outputOptions function provided by Shiny. From the help page for outputOptions,
suspendWhenHidden, when TRUE (the default), the output object will be suspended (not execute) when it is hidden on the web page. When FALSE, the output object will not suspend when hidden, and if it was already hidden and suspended, then it will resume immediately.
By specifying suspendWhenHidden = FALSE after defining the downloadHandler we can prevent the href problem described in the original question.
Below is a revised, working version of the small Shiny application included in the original question.
shinyApp(
ui = fluidPage(
tags$head(
tags$style(HTML(".hide { display: none; }")),
tags$script(HTML('
Shiny.addCustomMessageHandler("trigger-button", function(message) {
document.getElementById(message.button_id).click();
});
'))
),
div(
class = "disable",
downloadButton("download_shown", "Shown"),
div(
class = "hide",
downloadButton("download_hidden", "Hidden")
)
),
br(),
actionButton("trigger_shown", "I can trigger the visible button!"),
actionButton("trigger_hidden", "I can trigger the hidden button!")
),
server = function(input, output, session) {
output$download_shown <- downloadHandler(
filename = "sample.txt",
content = function(file) {
cat("I'm visible!\n", file = file)
}
)
outputOptions(output, "download_shown", suspendWhenHidden = FALSE)
output$download_hidden <- downloadHandler(
filename = "sample2.txt",
content = function(file) {
cat("I'm hidden!\n", file = file)
}
)
outputOptions(output, "download_hidden", suspendWhenHidden = FALSE)
observeEvent(input$trigger_shown, {
session$sendCustomMessage(
"trigger-button",
list(button_id = "download_shown")
)
})
observeEvent(input$trigger_hidden, {
session$sendCustomMessage(
"trigger-button",
list(button_id = "download_hidden")
)
})
}
)
Remember to place calls to outputOptions after assigning corresponding reactive expressions to output, otherwise outputOptions will raise an error.