gpt4 book ai didi

r - 是否可以在同一个 ui.R( Shiny )中同时使用绝对面板和 sliderInput?

转载 作者:行者123 更新时间:2023-12-04 11:32:57 24 4
gpt4 key购买 nike

这是我的 ui.R。这是 Shiny 教程中提供的示例。我刚刚编辑了它。

library(shiny)
library(markdown)
# Define UI for application that draws a histogram
shinyUI(fluidPage(

# Application title
titlePanel("Hello Shiny!"),

# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
absolutePanel(
bottom = 0, left=420, width = 800,
draggable = TRUE,
wellPanel(
em("This panel can be moved")

)
)

))
))

和我的服务器。 R

library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# Expression that generates a histogram. The expression is
# wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
# 2) Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})**

在这种情况下,sliderInput 不起作用。如果我删除绝对面板,sliderInput 就可以了。可能是什么问题?
非常感谢

最佳答案

absolutePanel 使用 jqueryui javascript 库。它有自己的 slider 。这会导致与使用 jslider 库的 sliderInput 发生冲突。您可以看到如下所示:

library(shiny)
runApp(
list(ui = fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput("distPlot")
, tags$head(tags$script(src = "shared/jqueryui/1.10.3/jquery-ui.min.js"))

)
)
),
server = function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
)
)

编辑:这已在 shiny 的最新开发版本中修复。 slider 组件已从 jqueryui inc 中删除。 https://github.com/rstudio/shiny/commit/7e12a281f51e047336ba2c501fcac43af5253225

关于r - 是否可以在同一个 ui.R( Shiny )中同时使用绝对面板和 sliderInput?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22834092/

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