Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:10:07+00:00 2026-06-15T18:10:07+00:00

Just playing with Shiny and loving it already. But how do I get charts

  • 0

Just playing with Shiny and loving it already. But how do I get charts in the reactivePlot / plotOutput combination to be of different sizes depending on which chart is plotted?

In this first example, I have selected the “Yield curve” analysis and get the aspect ratio I want:

enter image description here

But when I choose another analysis, in this case a heatmap, it is now the same size as the “Yield Curve” chart which distorts it (cells should be square, not rectangular).

enter image description here

How can I change the chart size depending on which chart has been selected? I’ve tried putting the height parameter = NA, NULL or “” but it doesn’t like any of those.

Separately, but in the same application, how can I get some whitespace between the top selectInput and the textInputs in the sidebarPanel? I have tried h4(” “) but doesn’t work.

Here is my ui.R:

library(shiny)

shinyUI(pageWithSidebar(
    headerPanel(h1("SAGB Relative Value Tool")),
    sidebarPanel(
        h4("Choose analysis:"),
        selectInput("analysis1", "", 
            choices = c("Yield curve", "Optical asset swap spreads", 
                        "Cheap dear box", "Cheap dear charts", "Switch signaliser", 
                        "Barbells")),
        h4(" "),
        h4("Yield override:"),
        lapply(bondNames, function(x)
            textInput(paste(x, "bond"), x, last(sagb$sagb)[x]))
    ),
    mainPanel(
        h3(textOutput("AnalysisHeader")),
        plotOutput("AnalysisOutput", height = "10in"))
))

and here is my server.r

library(shiny)

shinyServer(function(input, output) {

    output$AnalysisHeader  <- reactiveText(function() {
        input$analysis1
    })


    output$AnalysisOutput <- reactivePlot(function() {
        switch(input$analysis1,
            "Yield curve" = wo(whichOut = 1),
            "Optical asset swap spreads" = wo(whichOut = 2),
            "Cheap dear box" = wo(whichOut = 3),
            "Cheap dear charts" = wo(whichOut = 4),
            "Switch signaliser" = wo(whichOut = 5),
            "Barbells" = wo(whichOut = 6)
        )

    })


})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:10:09+00:00Added an answer on June 15, 2026 at 6:10 pm

    (sometimes it’s a good idea to RTFM (talking to my self as well, cf my comment to OP)

    reactivePlot(func, width = "auto", height = "auto", ...)
    
    width    The width of the rendered plot, in pixels; or ’auto’ to use the offsetWidth of
             the HTML element that is bound to this plot. You can also pass in a function
             that returns the width in pixels or ’auto’; in the body of the function you may
             reference reactive values and functions.
    *height* The height of the rendered plot, in pixels; or ’auto’ to use the offsetHeight
             of the HTML element that is bound to this plot. You can also pass in a function
             that returns the width in pixels or ’auto’; in the body of the function you may
             reference reactive values and functions.
    ...      Arguments to be passed through to png. These can be used to set the width,
             height, background color, etc.
    

    however, so far I couldn’t manage to make to work (with height="15in")…

    Error in switch(units, `in` = res, cm = res/2.54, mm = res/25.4, px = 1) *  : 
      non-numeric argument to binary operator
    

    EDIT: it’s now working, height has to be numeric, with optional units="px" and res certainly something to convert units to pixels.

    EDIT 2: and don’t forget to update Shiny [to the last version], it fixes some bugs I faced.

    EDIT 3: here is an example where the height is dynamically changed:

    getVarHeight <- function() {
        return(getNumberOfPlots() * 400)
    }
    output$out <- reactivePlot(doPlots, height=getVarHeight)
    

    You can relate the snippet to this screenshot, where getNumberOfPlots returns the number of graph to plot.

    EDIT 4: if you want to display several images, you should change the height in ‘ui.R’ as well: this value is directly transmitted to CSS, and the default value is 400px. So if your images are bigger, they will overlap and only the to 400px will be visible …

    plotOutput(outputId = "plot_rain", height="100%"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just playing around with some code but it seemed to have the specific
I'm just playing around with threads to get used to them, so I wanted
I was just playing around with ckeditor and can't get the darn thing to
Just playing around with interfaces and I have a question about something which I
I'm just playing with jqplot for a few hours but I couldn't find how
I'm just playing with the metaclass programming in Groovy. But suddenly I was facing
I'm just playing with attributes, which contains some info about a specific database field.
Just playing around with different types of bindings and having a property binding a
I am just playing around with the language, but wonder if it is possible
I'm just playing with the canvas and surfaceview to get a better understand however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.