Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

r - Increasing margins for base plot in RShiny (arguments to par() are not respected)

I am having issues with a Shiny App such that the text labels are being cut off. If I were performing this plotting in R, I would adjust the margins of the plotting area using par(mar = c(10,10,10,10)), or other adjustments.

However, when I attempt to adjust the margins using par() within a shiny app no change takes effect. Here is a sample shiny app where I attempt to adjust the margins without success:

server.R

library(shiny)

shinyServer(function(input, output) {

    output$distPlot <- renderPlot({

        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        
        par(mar = c(10,10,10,10))

        hist(x, breaks = bins, col = 'darkgray', border = 'white', main = "Obsequious people are usually not being genuine; they resort to flattery and other fawning ways to stay in the good graces of authority figures. An obsequious person can be called a bootlicker, a brownnoser or a toady.")

    })
})

ui.R

library(shiny)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

    # Application title
    titlePanel("Old Faithful Geyser Data"),

    # Sidebar with a slider input for number of bins
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a plot of the generated distribution
        mainPanel(
            plotOutput("distPlot")
        )
    )
))

Is it possible to use par() to define a plotting area for a shiny app?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...