简体   繁体   English

R shiny plot定位

[英]R shiny plot positioning

I am new to R shiny.我是 R shiny 的新手。 I am trying to position my plots right next to each other instead of one being at the top and the other below it.我正在尝试 position 我的地块彼此相邻,而不是一个在顶部,另一个在它下面。 I want my word cloud to be on the left and the bar plot to be on the right of the word cloud and both should be below the slider.我希望我的词云位于左侧,条形 plot 位于词云的右侧,两者都应位于 slider 下方。 Currently, they appear like this:目前,它们看起来像这样:

在此处输入图像描述

My UI code is:我的用户界面代码是:

tabPanel("Word Cloud",
         sidebarLayout(
             sidebarPanel(
                 sliderInput("numberInput2", "Maximum Number of Words:", min=1, max=105, 
                             value=30),
             ),
             mainPanel(
                 plotOutput("WordCloudPlot",  width="100%"),
                 br(), br(),
                 br(), br(),
                 br(), br(),
                 plotlyOutput("WordCloudBarPlot")
             )
         )
)

My Server code is:我的服务器代码是:

  wordcloud_rep <- repeatable(wordcloud)
    output$WordCloudPlot <- renderPlot({
        wordcloud_rep(names(v), v, scale=c(5,1),
                      min.freq = 20, max.words=input$numberInput2,
                      colors=brewer.pal(8, "Dark2"))
        }, width = 900, height = 600)
    
    d7<- reactive({
        dd %>%
            dplyr::top_n(input$numberInput2)
    })
        output$WordCloudBarPlot <-renderPlotly({
    a7 <- ggplot(d7(), aes(x=reorder(word, -frequency), y=frequency))+
        geom_bar(stat="identity", fill='steelblue')+theme_bw()+
        theme(plot.title = element_text(color = "black", size = 20, face = "bold", hjust = 0.5), 
              axis.title.x =element_text(color = "black", size = 14, face = "bold", hjust = 0.5),
              axis.title.y = element_text(color = "black", size = 14, face = "bold", hjust = 0.5))+
        labs(y = "Frequency",x="Words",title = "Word Cloud Frequency")+
        theme(axis.text.x = element_text(angle = 45, hjust = 1))
    ggplotly(a7, source = "select", tooltip = "frequency")
})

Inside of your mainPanel, place a fluidRow.在您的 mainPanel 中,放置一个 fluidRow。 In the fluidRow, place two columns with width=6.在fluidRow 中,放置两列width=6。 Place one plot in each of the columns:在每一列中放置一个 plot:

mainPanel(
  fluidRow(
    column(
      width = 6,
      plotOutput("WordCloudPlot",  width="100%")
    ),
    column(
      width = 6,
      plotlyOutput("WordCloudBarPlot")
    )
  )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM