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
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'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)
I apologize for a very novice question.
I'm learning to use R shiny dashboard to display live infographics of polls performed through google forms.
This is the trial form: https://forms.gle/pixQ2pui5Qmgh9A4A
And this is the url that may be used to extract the .csv output of its responses:
https://docs.google.com/spreadsheets/d/1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo/export?format=csv&id=1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo&gid=1120079968
I understand that the reactiveFileReader() function should update the data continuously, but this does not seem to work, and the plot does not get updated unless the page is refreshed manually. How can the data be made to update itself continuously instead?
Thanks all!
library(shiny)
library(shinydashboard)
ui <- shinyUI(
dashboardPage(
dashboardHeader(title = "Data streaming"),
dashboardSidebar(
menuItem("Plot")
),
dashboardBody(
fluidRow(
box(plotOutput("histogram"))
)
)
)
)
server <-
shinyServer(function(input, output, session){
form.url = "https://docs.google.com/spreadsheets/d/1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo/export?format=csv&id=1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo&gid=1120079968"
dat <- reactiveFileReader(1000,
session,
filePath=form.url,
readFunc = function(filePath) {
read.csv(url(filePath))
})
output$histogram <- renderPlot({
hist(dat()$N, cex.main="", xlab="Poll", breaks=5)
})
})
shinyApp(ui, server)
formr is a free solution to live poll visualisation with R. They can host your polls but you can also host your own.
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
I'm trying to get a Shiny reactive UI running. It is getting quite complex (in terms of lines of code) so I thought refactoring was a good idea. To put it short, this is my server code:
require(ggplot2)
require(h2o)
shinyServer(function(input, output, session) {
#stop()
localH2o <<- h2o.init(nthreads = 3) #Global variable
source("BuilderServer.R", local = TRUE)[1]
source("ReviewerServer.R", local = TRUE)[1]
# CleanupFUnctions
session$onSessionEnded(function() {
rm(list=ls())
})
})
where I assumed source with local = TRUE was just like copy-paste the content of the R files. So they contain functions of the form output$functionName <- renderUI({code}). The ui code depends on these functions, most of them are reactive, the ui code looks like this:
shinyUI(navbarPage("Metamodel",
tabPanel("Build Custom Model",
fluidRow(
column(12,align="center",
uiOutput("BuilderUpTitle")
)
),
fluidRow(
column(3,
uiOutput("BuilderAxisSelector")
)
)
)
))
In this particular case, the "BuilderUpTitle" function looks like this:
output$BuilderUpTitle <- renderUI({
inFile <- input$BuilderInputFile
if(is.null(input$BuilderInputFile)){
fileInput("BuilderInputFile", "Upload a xlsx file")
} else {
#R Stuff done here with the file
textInput("text", label = h3("Model Title"), value = "Enter text...")
}
})
I wrote the code yesterday and it was working. Today I turned on the computer again, and when launching the app, not even the dependencies from the server.R appear to load (ggplot2 and h2o). The download button from the "BuilderUpTitle" function doesn't appear at all and shiny appears to only execute the ui.R code. I set the workspace to the folder of the sourcefiles and it doesn't help. Even if I uncomment the stop() function from the server, nothing seems to change. Setting breakpoints in RStudio doesn't stop the code inside the server, so that is why I think shiny is not calling the server function. However, the code was working before and I did not modify a single file. I even copied the content of the source files to the server.R code and still they do not load. Is there something obvious that I'm missing? Thank you in advance!
Ok, once again, I found myself what the problem is, and none of the things I said would've made anyone find what was wrong. Here is the tiniest possible code that reproduces the problem:
ui.R
shinyUI(fluidPage(
fluidRow(
uiOutput("itWillLock"),
uiOutput("itWillLock")
)
))
server.R
shinyServer(function(input, output) {
output$itWillLock <- renderUI({
sliderInput("slider","Slider",min=0,max=1,value=0)
})
})
I guess R gets stuck in an infinite loop and never reaches the server.R file. Is this a bug that I should report? Or just common sense will keep people out of this trouble. Thank you!