#r #user-interface #ggplot2 #shiny
Вопрос:
Я разрабатываю блестящее приложение в R, и мне нужны некоторые указания о том, как улучшить макет приложения, сделав его более лаконичным. У меня есть несколько sidebarPanel
графиков в структурах столбцов, верхняя половина выглядит так:-
С еще несколькими сюжетами дальше. Тем не менее, я хотел бы, чтобы после первого сюжета некоторые сидели под sidebarPanel
и два на два, вот так:-
Вот мой код:-
#libraries ==================================== library(shiny) library(tidyverse) library(ggplot2) library(cluster) # clustering algorithms library(factoextra) # clustering algorithms amp; visualization #filter choices================================= choices1 = c("AAA","BBB","CCC","DDD") #ui=============================== uilt;-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 ========================== serverlt;-function(input,output,session){ #clustering scaledData lt;- scale(iris[,1:4]) irisCluster lt;- kmeans(scaledData, center=3, nstart=20) irisCluster output$scatterplotlt;-renderPlot({ scatter lt;- 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$boxplotlt;-renderPlot({ box lt;- 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$histogramlt;-renderPlot({ histogram lt;- 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$barplotlt;-renderPlot({ set.seed(1234) iris1 lt;- iris[sample(1:nrow(iris), 110), ] hline lt;- data.frame(Species=c("setosa", "versicolor", "virginica"), hline=as.vector(table(iris$Species))) hline bar lt;- 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$clusterplotlt;-renderPlot({ fviz_cluster(irisCluster, data = scaledData, geom = "") theme(axis.title.x = element_blank(), axis.title.y = element_blank()) }) } shinyApp(ui,server)
Может ли кто-нибудь показать мне настройки, которые мне нужно внести UI
, чтобы я мог получить желаемый результат?
Спасибо!
Ответ №1:
Вы можете поместить все остальные участки, кроме первого, в отдельный ряд, что-то вроде этого:
uilt;-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».
Комментарии:
1. Это именно то, что мне нужно. Спасибо!