Resize image using slider in Shiny

Purpose: To make the image resize in response to moving the slider in Shiny (RStudio). Think of a scalable effect.

Problem: The error "Error in basename (imageinfo $ src): expected character vector argument" appeared. I can not find anything that directly answers the question, and I'm not sure what else to try. Is this just a problem with how sliderInput is used as input $ slider in server.R?

My current progress:. My rationale was to set up the slider in the ui.R file, and then get the image width in the server.R file.

Part of ui.R:

shinyUI(fluidPage( titlePanel("Nancy Brainstorming"), sidebarLayout( sidebarPanel( h3( strong("What is this?", style = "font-si24pt")), p("This is a pilot project."), sliderInput("slider", label = "", min = 100, max = 300, value = 200), imageOutput("logo", width = 200) ) ) )) 

Part of server.R:

  shinyServer(function(input, output) { output$logo = renderImage({ img(src = "mylogo.png", width = input$slider) }) }) 

Additional Information: The image appears just fine when I use img (src = "mylogo.png", width = 200). In addition, I am doing this to better understand how to create brilliant applications.

+6
source share
1 answer

img(src = "mylogo.png", width = input$slider) just returns html. You can use renderUI instead of renderImage .

 library(shiny) runApp( list(ui = fluidPage( titlePanel("Nancy Brainstorming"), sidebarLayout( sidebarPanel( h3( strong("What is this?", style = "font-si24pt")), p("This is a pilot project."), sliderInput("slider", label = "", min = 100, max = 300, value = 200), uiOutput('logo') ), mainPanel( plotOutput("distPlot") ) ) ), server = function(input, output, session) { output$logo <- renderUI({ img(src = "http://i.stack.imgur.com/mTqXa.png", width = as.integer(input$slider)) }) } ) ) 

enter image description here

+5
source

Source: https://habr.com/ru/post/969396/


All Articles