i'm trying to show a logo in my Shiny app, but when i try to see i only can see a small icon, but not the image, this is my code:
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='C:/Users/carlo239/image[![enter image description here][1]][1]/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
And this is the issue, i tried to reload, but is not working,
I know that the image is ok, because if i click on Download i get the same image, but i'm unable to see in my outputs. THANKS !!
There are two ways:
Put the file in the www folder of your app (as suggested by #YBS). That is in most cases the recommended solution.
"Register" your folder as resource folder for your app (see below). However, that solution is intended to help package authors make resources available to the package's components. Also be aware that absolute paths can pose problems when you deploy your app.
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='/foo/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
addResourcePath("foo", "C:/Users/wherever/your/file/may/be/located")
}
shinyApp(ui, server)
Related
In my app, users should insert some data from an Excel file, but I want to make it possible for them to download one (TesteR.xlsx) in their computer and use it as an example. I have tried to apply this solution but it didn't work, when I click the button it downloads a kinda weird file.
library(shiny)
ui <- fluidPage(
downloadButton("downloadOP", label = "Download")
)
server <- function(input, output){
output$downloadOP <- downloadHandler(
filename = "ph1data",
content = function(file) {
file.copy("www/TesteR.xlsx", file)
}
)
}
shinyApp(ui, server)
I also included the file in a www folder like suggested in the other question, but maybe I am missing something.
Any help would be very much appreciated!
Make sure your www folder is in the same directory as your app.r or server.r/ui.r files. It must be readable by the shiny server.
As you don't state how your app is started/served (from your computer, on a server, what kind of server, using shiny/server, on shinyapps.io, shinyproxy, ...) further advice won't be very useful.
I will also add the file extension to filename = "ph1data.xlsx".
If you add a A tag to your UI, does it work ? (target="self" prevent opening a new tab)
ui <- fluidPage(
downloadButton("downloadOP", label = "Download"),
tags$a("Download", href="TesteR.xlsx", target="self")
)
If you put and image (eg test.jpg) in your www folder and add an IMG tag to your UI, does it show the image ?
ui <- fluidPage(
downloadButton("downloadOP", label = "Download"),
tags$a("Download", href="TesteR.xlsx", target="self", class="btn btn-primary"),
tags$img(src="test.jpg")
)
I have followed previous posts regarding embedding MP4 files into Shiny.
Here is what I have:
library(shiny)
ui <- shinyUI(fluidPage(
tags$video(id="video2", type = "video/mp4",src = "slide1a.mp4",controls = "controls")
)
)
server <- shinyServer(function(input, output, session) {
}
)
shinyApp(ui, server)
I have the file "slide4a.mp4" in the www folder.
When I run it, the controls appear but nothing else.
Any help much appreciated.
Sincerely,
Erin
I dont know why this simple code isnt working.
I've a file named app.R and a folder named www with a image named "cat.jpeg" inside.
I tried to use this:
ui <- fluidPage(
h6("My cat:"),
tags$img(src = "cat.jpeg")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
In the output, my image just doest not appear!
If I change the "cat.jpeg" for a url link it works normally.
I have been working on a shiny app that will allow users to pick a pdf from a file directory that is in the app and display it on screen using an iframe by letting users first select the folder that holds the pdfs, and then select a specific pdf inside of that folder. However, the way I have it setup now will not display the pdf on the screen, it instead shows a not found error in the iframe.
Here is my code:
library(shiny)
ui <- fluidPage(
headerPanel("Client"),
selectInput("folder", "Select the report type",
c(dir("Reports/"))),
conditionalPanel(
condition = "input.folder == 'Invoice Analysis'",
selectInput("report", "Choose the PDF",
choices = dir("Reports/Invoice Analysis"))),
conditionalPanel(
condition = "input.folder == 'Pole Attachments'",
selectInput("report", "Choose the PDF",
choices = dir("Reports/Pole Attachments"))),
htmlOutput("pdfviewer")
)
server <- function(input, output){
output$pdfviewer <- renderUI({
tags$iframe(src=(input$report), height=300, width=600)
})
}
shinyApp(ui = ui, server = server)
Here is the current output:
I can replace the src in the iframe with a website and it displays the site correctly.
example:
tags$iframe(src=("http://www.w3schools.com"), height=300, width=600)
This leads me to believe that somehow I am getting this section of my code wrong. I have also tried something like this:
tags$iframe(src=(paste0(input$folder, input$report), height=300, width=600)
but it gives me the same not found error. Can anyone think of a way to make the source of the iframe a selection from the user? I am very new at r and shinyapps so I don't know if this is a syntax problem, or if I am going about this the wrong way. Thank you in advance for the help.
I am rather new in shiny, so I was running through some tutorials. However, I have a problem loading images from a file inside the "www" folder of the shiny app.
For example, when I run the code below, I get a missing image. However, if I refer to an image online, e.g., if I substitute "bigorb.png" by "http://shiny.rstudio.com/tutorial/lesson2/www/bigorb.png", I get the desired image without problems. I am using R version 3.3.1 on Windows 10. Can anyone help me?
ui <- shinyUI(fluidPage(
titlePanel("My Shiny App"),
sidebarLayout(
sidebarPanel(),
mainPanel(
img(src="bigorb.png", height = 400, width = 400)
)
)
))
server <- shinyServer(function(input, output) {
})
shinyApp(ui = ui, server = server)
This works for me:
Create folder /myApp
Inside /myApp: create a file starter.R with the following code, and make sure to set the working directory correctly:
library(shiny)
setwd("PATH_TO_myApp")
shiny::runApp("app")
In the folder /myApp, create a subfolder /app.
In /myApp/app/: create file "app.R" with your code from above.
Create another sub-subfolder /myApp/app/www/ . Include your image file.
Execute starter.R.
So your file list is:
/myApp/starter.R
/myApp/app/app.R
/myApp/app/www/bigorb.png