2

您好,我创建了一个闪亮的应用程序,其中包括一个用 plotly 创建的散点图。我的问题是我无法增加轴标题(y)和轴标签之间的空间,尽管使用axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 20))基于增加 y 轴上文本和标题之间的灰尘 。每次更改输入时都会更新绘图,因此两个轴标题并且标签每次都会改变。

 #ui.r
    library(shiny)
    library(ggplot2)
    library(plotly)
    fluidPage(

      # App title ----
      titlePanel(div("CROSS CORRELATION",style = "color:blue")),

      # Sidebar layout with input and output definitions ----
      sidebarLayout(

        # Sidebar panel for inputs ----
        sidebarPanel(



        ),
        # Main panel for displaying outputs ----
        mainPanel(

          tabsetPanel(type = "tabs",
                      tabPanel("Table",
                               shiny::dataTableOutput("contents")),
                      tabPanel("Correlation Plot",
                               fluidRow(
                                 column(3, uiOutput("lx1")),
                                 column(3,uiOutput("lx2"))),
                               hr(),
                               fluidRow(
                                 plotlyOutput("sc"))
                      ))
          )))
    #server.r
    function(input, output) {


      output$contents <- shiny::renderDataTable({

        iris
      })


      output$lx1<-renderUI({
        selectInput("lx1", label = h4("Select 1st Expression Profile"), 
                    choices = colnames(iris[,1:4]), 
                    selected = "Lex1")
      })
      output$lx2<-renderUI({
        selectInput("lx2", label = h4("Select 2nd Expression Profile"), 
                    choices = colnames(iris[,1:4]), 
                    selected = "Lex2")
      })


      output$sc<-renderPlotly({

        p1 <- ggplot(iris, aes_string(x = input$lx1, y = input$lx2))+

          # Change the point options in geom_point
          geom_point(color = "darkblue") +
          # Change the title of the plot (can change axis titles
          # in this option as well and add subtitle)
          labs(title = "Cross Correlation") +
          # Change where the tick marks are
          scale_x_continuous(breaks = seq(0, 2.5, 30)) +
          scale_y_continuous(breaks = seq(0, 2.5, 30)) +
          # Change how the text looks for each element
          theme(title = element_text(family = "Calibri", 
                                     size = 10, 
                                     face = "bold"), 
                axis.title = element_text(family = "Calibri Light", 
                                          size = 16, 
                                          face = "bold", 
                                          color = "darkgrey"), 
                axis.text = element_text(family = "Calibri", 
                                         size = 11),
                             axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 20))
)+
          theme_bw()+
          geom_smooth(method = input$td)+
          annotate("text", x = 10, y = 10, label = as.character(input$an))
        ggplotly(p1) %>%
          layout(hoverlabel = list(bgcolor = "white", 
                                   font = list(family = "Calibri", 
                                               size = 9, 
                                               color = "black")))

      }) 




    }
4

0 回答 0