【问题标题】:Show text in shiny app when tabpanel is clean and hide it when output is displayed当tabpanel干净时在闪亮的应用程序中显示文本并在显示输出时隐藏它
【发布时间】:2020-12-13 07:58:26
【问题描述】:

我有一些图,一旦单击提交按钮就会显示,但在此之前,选项卡保持干净。我希望在此处显示一些文本,以便用户在点击提交按钮之前可以看到某些内容,并且在单击按钮后,我希望删除文本并且它必须显示绘图。

【问题讨论】:

    标签: r shiny shinyjs


    【解决方案1】:

    这是我对闪亮应用示例的看法:

    library(shiny)
    library(shinyjs)
    
    # Define UI for application that draws a histogram
    ui <- fluidPage(
        useShinyjs(),
        
        # Application title
        titlePanel("Old Faithful Geyser Data"),
        
        # Sidebar with a slider input for number of bins 
        sidebarLayout(
            sidebarPanel(
                sliderInput("bins",
                            "Number of bins:",
                            min = 1,
                            max = 50,
                            value = 30),
                actionButton("submit", "Show plot")
            ),
            
            # Show a plot of the generated distribution
            mainPanel(
                tabsetPanel(
                    tabPanel(
                        "Plot",
                        uiOutput("help_text"),
                        plotOutput("distPlot")
                    )
                )
            )
        )
    )
    
    # Define server logic required to draw a histogram
    server <- function(input, output) {
        
        output$help_text <- renderUI({
            HTML("<b>Click 'Show plot' to show the plot.</b>")
        })
        
        plot_data <- eventReactive(input$submit, {
            
            hide("help_text")
            
            # generate bins based on input$bins from ui.R
            x    <- faithful[, 2]
            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')
        })
        
        output$distPlot <- renderPlot({
            plot_data()
        })
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)
    
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2010-09-13
      • 2018-07-14
      相关资源
      最近更新 更多