简体   繁体   中英

R shiny plot positioning

I am new to 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. 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. 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. In the fluidRow, place two columns with width=6. Place one plot in each of the columns:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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