我正在用 R 開發一個閃亮的應用程式,我需要一些關于如何通過使其更簡潔來改進應用程式布局的指示。我sidebarPanel在列結構中有一些圖,上半部分看起來像這樣:-

隨著更多的情節進一步下降。然而,我想在第一個情節之后,有些人坐在下面sidebarPanel和兩個兩個,像這樣:-

這是我的代碼:-
#libraries ====================================
library(shiny)
library(tidyverse)
library(ggplot2)
library(cluster) # clustering algorithms
library(factoextra) # clustering algorithms & visualization
#filter choices=================================
choices1 = c("AAA","BBB","CCC","DDD")
#ui===============================
ui<-fluidPage(
titlePanel('Minimal example'),
tabsetPanel(
tabPanel("example text",
#sidebarLayout(
sidebarPanel(width = 4,
dateRangeInput("daterangeinput", "Select date range", format = "yyyy-mm-dd",
start = min("2021-06-05"),
end = max("2021-06-15")),
numericInput("start", "Select minimum",10,min=0, max=23),
numericInput("end", "Select maximum",22, min=0, max=23),
pickerInput("choice", "Pick something",
choices = choices1, options = list('actions-box'=TRUE,'live-search'=TRUE), multiple = T)),
mainPanel(fluidRow(
column(width = 8, h4("Cluster plot"), plotOutput("clusterplot", width = "100%")),
column(width = 8, h4("Scatter plot"),plotOutput("scatterplot", width="100%")),
column(width = 8, h4("Box plot"),plotOutput("boxplot", width ="100%")),
column(width = 8, h4("Histogram"),plotOutput("histogram", width ="100%")),
column(width = 8, h4("Bar plot"),plotOutput("barplot", width ="100%")))),
)#end of tabpanel
)#end of tabset panel
)#end of fluidpage/UI
#server ==========================
server<-function(input,output,session){
#clustering
scaledData <- scale(iris[,1:4])
irisCluster <- kmeans(scaledData, center=3, nstart=20)
irisCluster
output$scatterplot<-renderPlot({
scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width))
scatter geom_point(aes(color=Species, shape=Species))
xlab("Sepal Length") ylab("Sepal Width")
ggtitle("Sepal Length-Width")
})
output$boxplot<-renderPlot({
box <- ggplot(data=iris, aes(x=Species, y=Sepal.Length))
box geom_boxplot(aes(fill=Species))
ylab("Sepal Length") ggtitle("Iris Boxplot")
stat_summary(fun.y=mean, geom="point", shape=5, size=4)
})
output$histogram<-renderPlot({
histogram <- ggplot(data=iris, aes(x=Sepal.Width))
histogram geom_histogram(binwidth=0.2, color="black", aes(fill=Species))
xlab("Sepal Width") ylab("Frequency") ggtitle("Histogram of Sepal Width")
})
output$barplot<-renderPlot({
set.seed(1234)
iris1 <- iris[sample(1:nrow(iris), 110), ]
hline <- data.frame(Species=c("setosa", "versicolor", "virginica"), hline=as.vector(table(iris$Species)))
hline
bar <- ggplot(data=iris1, aes(x=Species))
bar geom_bar()
xlab("Species") ylab("Count") ggtitle("Bar plot of Sepal Length")
geom_errorbar(data=hline, aes(y=hline, ymin=hline, ymax=hline), col="red", linetype="dashed")
})
#cluster plot ======================
output$clusterplot<-renderPlot({
fviz_cluster(irisCluster, data = scaledData, geom = "")
theme(axis.title.x = element_blank(), axis.title.y = element_blank())
})
}
shinyApp(ui,server)
有人可以告訴我我需要對它進行UI哪些調整,以便我可以獲得所需的輸出嗎?
謝謝!
uj5u.com熱心網友回復:
您可以將除第一個之外的所有其他圖放在單獨的行中,如下所示:
ui<-fluidPage(
titlePanel('Minimal example'),
tabsetPanel(
tabPanel("example text",
#sidebarLayout(
sidebarPanel(width = 4,
dateRangeInput("daterangeinput", "Select date range", format = "yyyy-mm-dd",
start = min("2021-06-05"),
end = max("2021-06-15")),
numericInput("start", "Select minimum",10,min=0, max=23),
numericInput("end", "Select maximum",22, min=0, max=23),
shinyWidgets::pickerInput("choice", "Pick something",
choices = choices1, options = list('actions-box'=TRUE,'live-search'=TRUE), multiple = T)),
mainPanel(
fluidRow(
column(width = 8, h4("Cluster plot"), plotOutput("clusterplot", width = "100%"))
)
)
)
),
fluidRow(
column(width = 6, h4("Scatter plot"),plotOutput("scatterplot", width="100%")),
column(width = 6, h4("Box plot"),plotOutput("boxplot", width ="100%")),
column(width = 6, h4("Histogram"),plotOutput("histogram", width ="100%")),
column(width = 6, h4("Bar plot"),plotOutput("barplot", width ="100%"))
)
)
如果您希望左側的繪圖與側邊欄面板對齊,您可以將它們的寬度調整為“4”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358912.html
上一篇:繪制虛擬變數時,如何將x軸上的0.0,1.0更改為男性女性?
下一篇:R中樹狀圖的非葉節點中的標簽
