Home > Software engineering >  Error when trying to place input$something in front of "=" sign in a shiny app
Error when trying to place input$something in front of "=" sign in a shiny app

Time:01-28

I have the shiny app below in which I want to run the function detect_value_range_violations() but instead of the lifecycle in line 27 I want to put input$sel to change between lifecycle and qty but then I get error detect_value_range_violations(input$sel =

## app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(daqapo)
act<-structure(list(lifecycle = c(3, 3, 1, 1, 2, 2, 6, 6, 4, 4, 5, 
                             5), qty = c(31, 31, 31, NA, 9, 31, 28, 28, 6, 6, 3, 3)), row.names = c(NA, 
                                                                                                    -12L), class = c("activitylog", "log", "tbl_df", "tbl", "data.frame"
                                                                                                    ), case_id = "case_id", activity_id = "activity", resource_id = "resource", timestamps = c("start", 
                                                                                                                                                                                               "complete"))
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    selectInput("sel","Select",choices = colnames(act),selected = colnames(act)[1],multiple = F)
  ),
  dashboardBody(
    
      ))


server <- function(input, output) {
  
  valuerange<-reactive({
    vr<-act %>%
      detect_value_range_violations(
        #input$sel
        lifecycle = domain_numeric(from = 0, to = 5))
    
  })
  
  
  
}

shinyApp(ui, server)

CodePudding user response:

The detect_value_range_violations seems to use rlang under the hood so you can use the := operator to change parameters names. I can't get your example to run without error so I'll use the example from the help page for that function.

data("hospital_actlog")

varname <- "triagecode"
# varname <- input$sel  #--- would also work

detect_value_range_violations(activitylog = hospital_actlog,
     "{varname}" := domain_numeric(from = 0, to = 5))
  • Related