简体   繁体   English

shiny 中只有两个 actionButtons 之一响应

[英]only one of the two actionButtons responds in shiny

I have shiny app example as below.我有 shiny 应用程序示例,如下所示。 I need to have two selectInput controls and each selectInput only responds when I click on action button.我需要有两个selectInput控件,每个selectInput仅在我单击操作按钮时响应。

What I found is the first action Button applyNameFilter does not respond at all.我发现第一个动作 Button applyNameFilter根本没有响应。 It's not highlighted when hovered over.悬停时不会突出显示。 The second action button applyTimeFilter seems to be OK.第二个操作按钮applyTimeFilter似乎没问题。

Does anyone know why?有谁知道为什么? It's so weird... I have no clue how to fix that and looking for help here.这太奇怪了......我不知道如何解决这个问题并在这里寻求帮助。 Thanks a lot.非常感谢。

library(shinydashboard)
library(shiny)
library(shinyWidgets)
library(shinyjs)
library(dplyr)


df = data.frame(Name = c('A', 'B', 'C', 'A', 'B', 'C'),
       Year = c('2020', '2020', '2020', '2019', '2019', '2019'),
       Value = c(12, 33, 44, 55, 22, 11))

ui <- dashboardPage(
    dashboardHeader(title = "Example" ),
    dashboardSidebar(
        sidebarMenu(
            menuItem("tab", tabName = "tab", icon = icon("globe"))
        ) 
    ), 
    dashboardBody(

        useShinyjs(),

        tabItems(

            tabItem(tabName = "tab",

                    div(id = 'timeAllFilters',
                        box( width=12, background = 'green',

                             selectizeInput(inputId = 'year', 
                                            label='Select Year',
                                          choices = c('', '2020', '2019'),
                                          multiple=FALSE,
                                          options = list(
                                              maxItems = 1,
                                              placeholder = '',
                                              onInitialize = I("function() { this.setValue(''); }"))),

                             actionBttn(
                                 inputId = 'applyTimeFilter',
                                 label = "Apply", 
                                 style = "gradient",
                                 color = "danger",
                                 icon = icon("") ),
                             actionBttn(
                                 inputId = 'clearTimeFilter',
                                 label = "Clear", 
                                 style = "gradient",
                                 color = "danger",
                                 icon = icon("") ) 
                        )  #box
                    ), #div


                    div(id = 'nameAllFilters',
                        dropdown(
                            tags$h3("Filters"),
                            selectizeInput(inputId = 'name', 
                                           label='Select Name',
                                           choices = c('','A', 'B'),
                                           multiple=FALSE,
                                           options = list(
                                               maxItems = 1,
                                               placeholder = '',
                                               onInitialize = I("function() { this.setValue(''); }"))),

                            actionBttn(
                                inputId = 'applyNameFilter',
                                label = "Apply", 
                                style = "gradient",
                                color = "danger",
                                icon = icon("") ),
                            actionBttn(
                                inputId = 'clearNameFilter',
                                label = "Clear", 
                                style = "gradient",
                                color = "danger",
                                icon = icon("") ) 
                        )  #dropdown
                    ), #div

                    dataTableOutput('table')
            ) #tabItem
        ) #tabItems
    ) #dashboardBody
) #dashboardPage


server <- function(input, output, session) {


    df1 = reactive({
        input$applyTimeFilter
        isolate( df %>% filter(Year %in% input$year) )
    })

    # clear time filters 
    observeEvent(input$clearTimeFilter, {
        reset("timeAllFilters")
    })


    df2 = reactive({
        input$applyNameFilter
        isolate ( df1() %>% filter(Name %in% input$name) )
    })

    # clear name filters 
    observeEvent(input$clearNameFilter, {
        reset("nameAllFilters")
    })

    output$table = renderDataTable({
        DT::datatable(df2())
    })
}

shinyApp(ui = ui, server = server)

The issue appears to be with the actionBttn being inside box() .问题似乎在于actionBttnbox()内。 It works just fine without.没有它就可以正常工作。 Any chance you could find another way to get the same style without box() ?你有没有机会找到另一种没有box()的方式来获得相同的风格?

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM