r - Overlay fileInput on leaflet in shiny - html

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.

Related

R Shiny mailto hyperlink text opens google.com

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)

Refresh Shiny output and set focus to the desired part of page

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

Go back to previous link in shiny

I have a simple shiny application (app1) where when the user clicks on the action button (action 1), it is taking to another shiny application(app 2) in another tab.
But there is also another action button (action 2) in app2. So when the user clicks on action 2, it should take him to the previous page(app1). Can we do this?
library(shiny)
ui <- fluidPage(
actionButton("aid","Click here")
)
server <- function(input, output, session) {
observeEvent(input$aid{
#### open another link(shiny application) in the browser (different tab)
})
}
shinyApp(ui, server)
very easy, we don't need any server expression, do this:
library(shiny)
ui <- fluidPage(
actionButton(
"aid", "Click here",
onclick = 'window.open("https://www.google.com", "_self")'
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
change the link to Google to your app1 link.If you want to open in another tab, remove the "_self".
or this can also work: onclick = 'location.href = "https://www.google.com";'

How to adjust the font of an URL in an R shiny app?

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)

How to print file to Shiny using renderText

I'm missing something here because the image doesn't display.
Thanks.
shinyServer(function(input, output) {
src = "einstein.jpg"
print(file.exists(src))
out = '<img src="einstein.jpg" style=width:304px;height:228px;>'
output$text3<-renderText(out)
})
shinyUI(fluidPage(
htmlOutput("text3")
))
If you put your picture einstein.jpg in a img/ subfolder of your app, you can use addResourcePath to allow access to it:
library(shiny)
shinyApp(ui=fluidPage(htmlOutput("text3")),
server=(function(input, output) {
addResourcePath("foo", "img")
out = '<img src="/foo/einstein.jpg" style=width:304px;height:228px;>'
output$text3<-renderText(out)
}))