gpt4 book ai didi

r - 侧边栏 Shiny 太长怎么办?

转载 作者:行者123 更新时间:2023-12-04 00:39:36 27 4
gpt4 key购买 nike

在下面的玩具示例中,我在侧边栏中有很多 slider 。对于最后一个,我再也看不到正确的情节了。这个问题有什么不涉及删除 slider 的解决方案吗?

# 01-kmeans-app

palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))

library(shiny)

ui <- fluidPage(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected = names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
),
mainPanel(
plotOutput('plot1')
)
)

server <- function(input, output) {

selectedData <- reactive({
iris[, c(input$xcol, input$ycol)]
})

clusters <- reactive({
kmeans(selectedData(), input$clusters)
})

output$plot1 <- renderPlot({
par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})

}

shinyApp(ui = ui, server = server)

最佳答案

您可以尝试在侧面板中添加一个向下滚动条

感谢 R shiny scroll wellPanel

# 01-kmeans-app

palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))

library(shiny)

ui <- fluidPage(
headerPanel('Iris k-means clustering'),
sidebarPanel(id = "tPanel",style = "overflow-y:scroll; max-height: 600px; position:relative;",
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected = names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
),
mainPanel(
plotOutput('plot1')
)
)

server <- function(input, output) {

selectedData <- reactive({
iris[, c(input$xcol, input$ycol)]
})

clusters <- reactive({
kmeans(selectedData(), input$clusters)
})

output$plot1 <- renderPlot({
par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})

}

shinyApp(ui = ui, server = server)

关于r - 侧边栏 Shiny 太长怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34278762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com