Unable to embed an mp4 video in Shiny R from computer - r

The result is a black background where the video should be playing.
The video is in the directory of the getwd() in R.
This is the code:
library(shiny)
ui <- shinyUI(
fluidPage(
tags$video(src="videoname.mp4", type = "video/mp4",height ="400px", width="400px",controls="controls")
)
)
server <- shinyServer(function(input, output, session) {})
runApp(list(ui = ui, server = server), launch.browser =T)

Related

R - shiny app - ERROR: Invalid git repo specification: 'ShinySky'

I try to run a shiny app on R studio, I get the error
"ERROR: Invalid git repo specification: 'ShinySky'"
with the message at the console:
"there is no package called ‘shinysky’
Warning: Error in parse_repo_spec: Invalid git repo specification: 'ShinySky'"
Any ideas how to resolve the issue?
install.packages("shiny")
library(shiny)
ui <- fluidPage(
sliderInput(inputId ="num", label = "Choose the sample size", value=5,
min=1, max=25 ),
plotOutput("hist")
)
server <- function(input, output, session) {
output$hist <- renderPlot({
hist(rnorm(input$num))
})
}
shinyApp (ui, server)

Shiny App Issue, ShinyDirButton is unresponsive

This code should produce a pop up that allows Directory Selection for a Shiny App.
However, when I run the code the button appears but is unresponsive in both the R-studio viewer and when run in a web-browser.
Does the code work for you? Is there anything that I am not doing right?
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyDirButton('folder', 'Select a folder', 'Please select a folder', FALSE)
)
server <- function(input, output){
volumes = getVolumes() # this makes the directory at the base of your computer.
observe({
shinyDirChoose(input, 'folder', roots=volumes, filetypes=c('', 'txt'))
print(input$folder)
})
}
shinyApp(ui=ui, server=server)
Thank you in advance
I found a different function that works, choose.dir().
library(shiny)
library(shinyFiles)
ui <- fluidPage(
actionButton("dir", 'select a folder'),
textOutput("wd") #display working directory
)
server <- function(input, output) {
observeEvent(input$dir, {
setwd(choose.dir("c:/")) #selecting a directory
output$wd <- renderText(getwd())})
}
shinyApp(ui = ui, server = server)

How to use the results of a reactive expression in an output

I'm trying to build a Shiny App that monitors my running containers on a host machine, and here is what I have tried so far. Question is how can I display the outputs, in this case (docker ps -a) contents in the mainPanel? I'm new to Rshiny, so any help will be much appreciated!
library(shiny)
library(ssh)
ui <- fluidPage(
titlePanel("Dashboard"),
sidebarLayout(
sidebarPanel(
actionButton("bttn", "Click")
),
mainPanel(
h1("Running containers"),
textOutput("dispContainers")
)
)
)
# Define server logic
server <- function(input, output, session) {
session <- ssh_connect("jeroen#dev.opencpu.or")
observeEvent(input$bttn, {
ssh_exec_wait(session, command = 'docker ps -a')
})
}
# Run the application
shinyApp(ui, server)
You can use the other ssh_exec_internal instead to collect the output of your docker command. Something like:
server <- function(input, output, session) {
session <- ssh_connect("jeroen#dev.opencpu.or")
text_output <- reactiveVal("")
observeEvent(input$bttn, {
response <- ssh_exec_internal(session, command = 'docker ps -a')
text_output(rawToChar(response$stdout))
})
output$dispContainers <- renderText(text_output())
}
You might also want to switch textOutput to verbatimTextOutput to get the text as you'd see it in a terminal.

R Shiny GoogleSheets4: Authentication error in Shinyio server on deployment?

Here is my code for a simple test app:
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(googledrive)
library(DT)
drive_auth(email = "xxxx")
shinyws1<-gs4_create("WS1")
#table<-read_sheet("xxx")
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Test App"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
numericInput("bins",
"Number of friends:",
min = 1,
max = 100,
value = 50),
actionButton("submit","Submit",class="btn-success")
),
# Show a plot of the generated distribution
mainPanel(
#blank so far
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#results<-reactive(input$bins)
observeEvent(input$submit,{
shinyws1 %>% sheet_append(as.data.frame(input$bins))
})
}
# Run the application
shinyApp(ui = ui, server = server)
It works okay in my local server. But deployment fails.
Here is the error message generated after deployment in Shinyio server:
Error in value[[3L]](cond) : Can't get Google credentials.
Are you running googledrive in a non-interactive session? Consider:
* `drive_deauth()` to prevent the attempt to get credentials.
* Call `drive_auth()` directly with all necessary specifics.
* Read more in: https://gargle.r-lib.org/articles/non-interactive-auth.html
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Does anyone know how to fix it? I've tried every workaround I found online, but it didn't work.

How to remove tags in textOutput - RShiny

I am new to R and I am actually developing a page where a directory (string characters like "xx/xx") is given in the server and I want to take back this directory to include it in the source of my ui app.
UI:
library(shiny)
file<-textOutput("paramfile")
source(file(file), local = TRUE, encoding = 'UTF-8')
SERVER :
filedir<-renderText({
"entries/5429_param.R"
})
output$paramfile<-renderText({
filedir()
})
I then have an error :
"Warning in file(filename, "r", encoding = encoding) : cannot open
file '< div id="paramfile" class="shiny-text-output">< /div>':
Invalid argument
Error in file(filename, "r", encoding = encoding) :
cannot open the connection"
Do you know how can I remove those tags or if there is another function that can allow me to take a string in the server and to include it into a source.
Here is a basic example of a ShinyApp:
# Example of UI with fluidPage
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput("dir", label = "Enter a directory")
),
mainPanel(
verbatimTextOutput("dirPrint"),
verbatimTextOutput("lsFiles")
)
)
)
# Server logic
server <- function(input, output) {
output$dirPrint <- renderPrint({
print(input$dir)
})
output$lsFiles <- renderPrint({
fls <- list.files(input$dir)
print(fls)
})
}
# Complete app with UI and server components
shinyApp(ui, server)
If you enter the path of a directory in the textinput, the second renderPrint function is showing all files, that are found at that path.
I would suggest you go over the Shiny-Tutorials, as there seem to be some syntax-problems in your code and I am not sure what exactly you want to achieve.

Resources