0

我想将我的整个代码放在操作按钮中。当我单击按钮时,我的整个代码仪表板应该在我的屏幕中可见(我现在正在我的代码中看到)但首先我必须只能看到那个按钮。

这是我试图放入按钮的示例仪表板。我没有在这段代码中制作按钮,因为这很简单。有人可以帮忙吗?

     library(shinydashboard)

 ui <- dashboardPage(
   dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
   dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(plotOutput("plot1", height = 250)),

       box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
    )
 )
)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
   hist(data)
  })
   }

shinyApp(ui, server)
4

1 回答 1

0

您可以req在输出中使用,例如:

output$plot1 <- renderPlot({
    req(input$button)
    data <- histdata[seq_len(input$slider)]
   hist(data)
  })

然后只有在使用输入时才会显示输出。

你也可以把东西放进去conditionalPanel()。您可以在脚本的 UI 部分使用它。例如:

fluidRow(conditionalPanel(condition = "input.button == true",
      box(plotOutput("plot1", height = 250)),

       box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
)

请注意,条件是在 javascript 中。

我已经为您的按钮命名并使其为 TRUE/FALSE,但您需要根据输入按钮进行调整。

于 2019-04-16T13:46:58.400 回答