I have a blog that uses Netlify. So, if I want to embed an interactive element, I believe I need to use an iframe.
The interactive element I wish to use is a simple image carousel.
library("slickR")
img <- c("img1.png",
"img2.png",
"img3.png",
"img4.png")
slickR(obj = img, slideId = 'ex1', height = 675, width = 540)
To create a stand alone page that just contains an image carousel do I need to use shiny-server to convert the R into css, HTML, Javascript?
If so, here's my attempt. Please advise as to what is wrong.
library(shiny)
library(htmlwidgets)
library(slickR)
ui = fluidPage(
htmlwidgets::shinyWidgetOutput(outputId = , "carousel",
name = "img_carousel",
width = "550px",
height = "600px")
)
server = function(input, output) {
img <- c("img1.png",
"img2.png",
"img3.png",
"img4.png")
slickR_obj <- slickR(obj = img, slideId = 'ex1', width = 540, height = 675)
output$carousel <- htmlwidgets::shinyRenderWidget(slickR_obj)
}
shinyApp(ui = ui, server = server)
Shiny server is required for shiny apps. What you wrote is a shiny app. But you can easily convert it to an rmarkdown document or flexdahsboard, which WILL be just html that can render anywhere. If you aren't familiar with either of these, they're both rstudio packages for creating html reports in R.
Related
I would like to display in my web application an SVG image that I have hosted in the images folder. First I tried to display it with a tag but it didn't work:
ui <- fluidPage(
tags$img(src = "./images/SVG_Logo.svg", width = "99px")
)
Then I used the rsvg and htmltools packages:
library(shiny)
library(htmltools)
library(rsvg)
#Load SVG image
miLogo <- rsvg_svg("./images/SVG_Logo.svg", width = 99)
miLogo_html <- as.character(miLogo)
ui <- fluidPage(
HTML(miLogo_html)
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
But I couldn't get it to work either. In both cases the browser displays this:
But if I replace the source path for example by: https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg
It works correctly
Could someone help me, please?
Best regards,
Wardiam
This code works for me. I had to create an images folder inside the www folder. Have you created a www folder to store your assets?
library(shiny)
library(htmltools)
ui <- fluidPage(
# tags$img(src = "https://raw.githubusercontent.com/paladinic/data/main/LINEA_black.svg", width = "99px")
tags$img(src = "./images/logo.svg", width = "99px")
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
I'm having some trouble displaying icons with sparklines within a DT::datatable column in a Shiny app even though I have escaped the HTML.
Edit: Removed 2nd question.
library(shiny)
library(dplyr)
ui <- fluidPage(
htmlwidgets::getDependency('sparkline'),
DT::dataTableOutput("table")
)
server <- function(input, output) {
raw_data <- data.frame(date = 2000:2021,
value = sample(100:500, 22),
icon = as.character(icon("arrow-up")))
data <- raw_data %>%
group_by(icon) %>%
# Create the sparkline
summarise("value" = sparkline::spk_chr(c(value),
xvalues = date,
tooltipFormat = '{{x}}: {{y}}'))
output$table <- DT::renderDataTable({
cb <- htmlwidgets::JS('function(){debugger;HTMLWidgets.staticRender();}')
DT::datatable(data = data,
escape = FALSE,
options = list(drawCallback = cb))
})
}
shinyApp(ui, server)
By default, the shiny::icon function:
generates the HTML code corresponding to the icon;
generates a script tag which includes the font-awesome icon library.
When you do as.character(icon(......, you only get the HTML code. The font-awesome library is not loaded, that's why the icon does not display.
The simplest way to get the icon is to use the glyphicon icon library, which is included in bootstrap so there's nothing to load (since bootstrap is loaded in Shiny apps):
as.character(icon("arrow-up", lib = "glyphicon"))
If you really want a font-awesome icon, there are two possibilities:
include the font-awesome library with a link tag;
or use the icon function elsewhere in your app, without as.character (you can hide it with the display:none CSS property if you don't want to see this icon) as shown below.
# add inside ui
tags$span(icon("tag"), style = "display: none;")
textInput(paste0("inp1-", wid),label = NULL,value = record$Current_week)
This is the code I used to create the text input boxes dynamically, the id for the text input box depends on the wid(which is a number).
I tried using following CSS format to change the background color, but it didn't work.
tags$head(tags$style(HTML('#',paste0("inp1-", wid),'{background-color:#f1c232;}')))
Please help me in solving this problem.
See here for an example where the input is not created dynamically. In your case, you could do as follows:
library(shiny)
wid=2
ui <- fluidPage(
uiOutput("my_ui")
)
server <- function(input, output) {
output$my_ui <- renderUI({
tagList(
textInput(paste0("inp1-", wid),label = NULL,value = 0),
tags$style(paste0("#inp1-", wid,"{background-color:#ff0000;}"))
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Hope this helps!
In my current project, I am trying to load images to shiny dashboard using R. The code snippet is as shown below:
dashboardBody(
hr(),
fluidRow(
column(6,align="center",imageOutput("ginger"))
)
)
)
server <- function(input, output) {
output$ginger <- renderImage({
return(list(
src = "images/ginger.jpg",
contentType = "image/jpeg",
width = 300,
height = 200,
alt = "Face"
))
}, deleteFile = FALSE)
Basically, it just display the image on the shiny dashboard. Here the image is stored in the local machine. Now, I want to load image from google drive or from the web. I am trying to load the image from my google drive and URL is https://drive.google.com/file/d/0By6SOdXnt-LFaDhpMlg3b3FiTEU/view.
I could not able to figure out that how to load images from google drive or web in shiny and how to add title in the image also? Am I missing something?
This answer is instructive. Here's a barebones shiny app with an external image call to display the image that you mention on your Google Drive account.
library(shiny)
# Define UI with external image call
ui <- fluidPage(
titlePanel("Look at the image below"),
sidebarLayout(sidebarPanel(),
mainPanel(htmlOutput("picture"))))
# Define server with information needed to hotlink image
server <- function(input, output) {
output$picture <-
renderText({
c(
'<img src="',
"http://drive.google.com/uc?export=view&id=0By6SOdXnt-LFaDhpMlg3b3FiTEU",
'">'
)
})
}
shinyApp(ui = ui, server = server)
I have a Shiny app that returns a character string containing the direct URL to an image hosted on the web. I am trying to find a way to display this image directly as an output.
When using renderImage() with src = "image url" the app does not display the image.
Here is an example of the problem:
ui.R
library(shiny)
shinyUI(fluidPage(
headerPanel("render externally hosted Image example"),
mainPanel(
# Use imageOutput to place the image on the page
imageOutput("myImage")
)
))
server.R
library(shiny)
shinyServer(function(input, output, session) {
output$myImage <- renderImage({
list(src = "http://data-informed.com/wp-content/uploads/2013/11/R-language-logo-224x136.png",
contentType = 'image/png',
width = 224,
height = 136,
alt = "This is image alternate text")
})
})
Any help is appreciated!
You could use htmlOutput() in the ui and renderText() in server.
Server.r
src = "https://theWeb/aPictureSomewhere.jpg"
output$picture<-renderText({c('<img src="',src,'">')})
ui.r
htmlOutput("picture")