这是我的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")

      )
)

  ))
))


和我的server. 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库。它有自己的滑块。这导致与使用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的最新开发版本中修复。滑块组件已从jqueryui inc中删除。 https://github.com/rstudio/shiny/commit/7e12a281f51e047336ba2c501fcac43af5253225

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

10-09 00:15