小编Wis*_*rag的帖子

如何在闪亮的情况下创建 On load 事件或默认事件?

我是闪亮和 stackoverflow 的新手,正在寻找有关我目前遇到的问题的帮助。我正在尝试构建一个闪亮的应用程序,它从用户那里收集一些输入,并根据单击按钮的输入创建可视化。目前,这工作正常,但一个主要问题是,当应用程序第一次加载时,它应该根据默认输入准备可视化。

我正在粘贴一个示例代码,它可以解释我面临的问题:

用户界面

  #loading shiny
  library(shiny)
  
  ui<-shinyUI(fluidPage(
    titlePanel("Iris Dataset"),
    sidebarLayout(
      sidebarPanel(
        radioButtons("x", "Select X-axis:",
                     list("Sepal.Length"='a', "Sepal.Width"='b', "Petal.Length"='c', "Petal.Width"='d')),
        radioButtons("y", "Select Y-axis:",
                     list("Sepal.Length"='e', "Sepal.Width"='f', "Petal.Length"='g', "Petal.Width"='h')),
        actionButton("action","Submit")
      ),
      mainPanel(
        plotOutput("distPlot")
      )
    )
  ))
  
  #SERVER.R
  library(shiny)
  
  #loading shiny
  server<-shinyServer(function(input, output) {
    
    observeEvent(input$action,{
    output$distPlot <- renderPlot({if(input$x=='a'){i<-1}
      
      if(input$x=='b'){i<-2}
      
      if(input$x=='c'){i<-3}
      
      if(input$x=='d'){i<-4}
      
      if(input$y=='e'){j<-1}
      
      if(input$y=='f'){j<-2}
      
      if(input$y=='g'){j<-3}
      
      if(input$y=='h'){j<-4}
      
      s    <- iris[, i]
      k    <- iris[, j]
      plot(s,k)
    })
  })
  })
  
  
  shinyApp(ui<-ui, server<-server)
Run Code Online (Sandbox Code Playgroud)

现在,如果您运行此应用程序,您会看到在加载后的第一个屏幕上选择了输入(这是所需的),但仅在单击“提交”按钮后才会出现可视化,这是因为观察者事件。在实际的应用程序中,在单击按钮时捕获输入后正在执行计算。因此,计算仅在单击 actionButton 时触发

有没有办法,我们仍然可以保留“提交”按钮及其观察事件,但会在开始时自动触发可视化或观察事件中执行的操作,即当应用程序第一次加载时。

r shiny shinydashboard shinyjs

7
推荐指数
1
解决办法
6346
查看次数

单击标题时展开/折叠闪亮框

我开发了一个闪亮的应用程序,我们在用户界面中使用各种框对象。目前,通过单击框标题右侧的“+/-”符号来展开/折叠框,但我们需要单击标题(框标题上的任何位置)来展开/折叠。下面的代码(示例代码)如果您查看带有图表的框,我希望在单击标题时执行展开和折叠,即“直方图框标题”,而不仅仅是标题右侧的“+/-”符号:

    ## Only run this example in interactive R sessions
    if (interactive()) {
      library(shiny)

      # A dashboard body with a row of infoBoxes and valueBoxes, and two rows of boxes
      body <- dashboardBody(
        # Boxes
        fluidRow(
          box(title = "Histogram box title",
              status = "warning", solidHeader = TRUE, collapsible = TRUE,
              plotOutput("plot", height = 250)
          )
        )


      )

      server <- function(input, output) {

        output$plot <- renderPlot({
          hist(rnorm(50))
        })
      }

      shinyApp(
        ui = dashboardPage(
          dashboardHeader(),
          dashboardSidebar(),
          body
        ),
        server = server
      ) …
Run Code Online (Sandbox Code Playgroud)

r shiny shinydashboard

4
推荐指数
1
解决办法
5195
查看次数

标签 统计

r ×2

shiny ×2

shinydashboard ×2

shinyjs ×1