Why is my image on shiny application is crashed? - r

Despite renaming my application to app.r and adding a source path to my code the added image turned from blue "?" to a crashed image ! what's the problem with it ? can anyone help me?
here is my code
ui <- fluidPage( helpText(
h4("Powerd by")),
tags$a(href='http://data-expert.net/',tags$img(src="<alidata.png>",height='50',width='120'),align='center'),
)
server <- function(input, output) {
addResourcePath(prefix = "img",
directoryPath = "C:/Users/Ali-Frady/Desktop/STAGE 2/DE")
shinyApp(ui = ui, server = server)

I've found the solution: It was about putting the image into a file called "www" and this file is at the same directory of the project already

Related

R Shiny "Not found" error in iframe for viewing PDF from local machine

I am trying to display a pdf file, which is stored in www folder.
My code:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(tabItem(tabName = "test",
tabBox(tags$iframe(style='height:400px; width:100%; scrolling=yes',
src="www/test.pdf"))))
)
server <- function(input, output) { }
shinyApp(ui, server)
If I run file.exists("www/test.pdf"), the answer is TRUE.
The www folder is placed in the same directory as app.r file.
Obviously, I am doing something wrong and maybe don't understand how to display the file that is stored on a local disc and not on the web. How to deal with this?
ok, I found the problem. I should only put:
dashboardBody(tabItem(tabName = "test",
tabBox(tags$iframe(style='height:400px; width:100%; scrolling=yes',
src="test.pdf")
src argument should be without www/

Make my existent Excel file available for users to download in shiny app

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")
)

Still having trouble with embedding an MP4 into shiny

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

unable to see output image in R shiny

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)

Immediately seeing changes in R shiny UI, in the browser, after making changes in code without having to restart the server?

Is it possible to see the changes in UI (only the UI and not server) after I make changes in my code, without having to restart the server/refresh the page? If cache needs to be cleared, can that also be done?
You could use reactiveFileReader to regularly source the code you'd save in another file, and renderUI()/uiOutput to display that dynamic UI:
app.R
library(shiny)
ui <- uiOutput("ui")
server <- function(input, output, session) {
ui <- reactiveFileReader(1000, session, "source.R", source)
output$ui <- renderUI(ui())
}
shinyApp(ui = ui, server = server)
source.R
fluidPage(
textInput("text", "text"),
textInput("text2", "text")
)
You still have to find out howto get rid of that "TRUE":

Resources