logo
down
shadow

Using conditionalpanel in shiny where input is a vector


Using conditionalpanel in shiny where input is a vector

By : Satyavathi Vanka
Date : October 22 2020, 08:10 PM
I hope this helps . I have a number of inputs that I would like to have to filter a data source. However, I have 100s of inputs to render but I expect only a handful will be used at any one point in time. , From the help:
code :
condition   
A JavaScript expression that will be evaluated repeatedly to determine whether the 
panel should be displayed.


Share : facebook icon twitter icon
conditionalPanel in R/shiny

conditionalPanel in R/shiny


By : David Kakaladze
Date : March 29 2020, 07:55 AM
Hope this helps Hi you can create a condition for conditionalPanel in the server like this :
code :
n <- 200
library("shiny")

# Define the UI
ui <- bootstrapPage(
  numericInput('n', 'Number of obs', n),
  conditionalPanel(condition = "output.cond == true", # here use the condition defined in the server
                   plotOutput('plot') ),
  HTML("Bottom")
)

# Define the server code
server <- function(input, output, session) {
  output$plot <- renderPlot({
    if (input$n > 50) hist(runif(input$n)) else return(NULL)
  })
  # create a condition you use in the ui
  output$cond <- reactive({
    input$n > 50
  })
  outputOptions(output, "cond", suspendWhenHidden = FALSE)
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)
Two conditionalPanel's in Shiny

Two conditionalPanel's in Shiny


By : Pastverb
Date : March 29 2020, 07:55 AM
hope this fix your issue The problem you are facing comes from having two almost identical elements in your ui, that share the same id. Conditional panels only hide your elements, but they are still there in the document. So your first numericInput will always be the one registered by Shiny and the second one will not be bound (i.e. will not send its input) to Shiny because of the duplicate id.
I advise you to implement the situation in a different way. There are functions in Shiny that let you change some existing ui element when the app is all set up. Those functions are updateXxxInput and you can change any variable there is in the corresponding input element. Since your only target is to change the max value of the numericInput, we can do this easily from the server, where we can observe the levels or any other variable. In the code below, I used a simple checkbox. The command for changing the max value is updateNumericInput(session, "centerpoints", max = 0). Note that this only changes the one attribute of you input. This is a huge advantage over re-rendering UI elements, since you don't have to keep track what all other attributes are.
code :
library(shiny)

ui <- shinyUI(
  fluidPage(
    numericInput("centerpoints", "Number of center points", value=0, min=0, max=25),
    checkboxInput("changeCenterpoints", "Cap maximum at 0")
  )
)

server <- function(input, output, session){
  observeEvent(input$changeCenterpoints, {
    if(input$changeCenterpoints){
      updateNumericInput(session, "centerpoints", max = 0, value = 0)
    }else{
      updateNumericInput(session, "centerpoints", max = 25)
    }
  })
}

shinyApp(ui, server)
Evaluating beyond input conditions in R Shiny conditionalPanel

Evaluating beyond input conditions in R Shiny conditionalPanel


By : Timbo Slice
Date : March 29 2020, 07:55 AM
it fixes the issue There is no reason to write reactives to conditionally show/hide elements. Take a look at shinyjs instead by Dean Attali
Example of using shinyjs:
code :
library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  actionButton("show", "Click me once to show stuff!"),
  actionButton("toggle", "Click me any times to toggle stuff!"),
  hidden(
    div(id = "d1",
      "Content hidden until button is clicked"
    )
  ),
  hidden(
    div(id = "d2",
        "Content toggled when button is clicked"
    )
  )
)

server <- function(input, output) {
  observeEvent(input$show, {
    show("d1")
  })

  observeEvent(input$toggle, {
    toggle("d2")
  })
}
shinyApp(ui, server)
Include a conditionalPanel in a Shiny module with condition based on global input

Include a conditionalPanel in a Shiny module with condition based on global input


By : imoogi
Date : March 29 2020, 07:55 AM
will help you Simple fix - The condition should be condition = input.check instead of condition = output.check.
condition as a vector in conditionalPanel using shiny

condition as a vector in conditionalPanel using shiny


By : user3029144
Date : March 29 2020, 07:55 AM
Does that help I turned multiple to FASLE because I'm not sure what's the desired condition in your mind if there is overlap.
How it works is that you need to insert your javascript array in your UI first. Also, your javascript syntax in the condition is wrong, the correct one should be:array1.indexOf(input.control) > -1
code :
#  ----
library(shiny)
library(shinydashboard)

# header ----
header <- dashboardHeader(title = "Example")

#sidebar ----
sidebar <- dashboardSidebar(disable = T)

#body ----
body <- dashboardBody(
  # insert javascript code in UI -----------------------
  tags$head(
    tags$script("var array1 = ['a','c', 'f'];")
  ),

  fluidRow(
    column(
      width = 12,
      selectInput(
        inputId = "control", 
        label = "choose something:",
        choices = c("a", 
                    "b", 
                    "c", 
                    "d", 
                    "e",
                    "f"),
        multiple = FALSE
      )
    )
  ),

  conditionalPanel(
    condition = "array1.indexOf(input.control) > -1", # change code here
    textInput(inputId = "first", label = "first test")
  )

)

# all ui ----
ui <- dashboardPage(
  header = header, 
  sidebar = sidebar, 
  body = body
)

# server ----
server = shinyServer(function(input, output) {

})
# Run the application 
shinyApp(ui = ui, server = server)
Related Posts Related Posts :
  • root undoing previous changes after sudo su user
  • Create X509 Certificate from.p12 or .pem certificate
  • Keras layer.set_weights doesn't modify the layer. Why?
  • Available build tasks in TFS 2017
  • Change oracle apex database user
  • How to parse typesafe config with objects
  • Is "Comment" a protected word in the Open API 3.0 spec or Swagger Editor?
  • Display Percentage in a Row in Tableau
  • Bokeh Colorbar Vertical title to right of colorbar?
  • Why the multi-ports model can't import into C++?
  • Nativescript tab page textfield
  • Why does this greedy algorithm work?
  • Nested list mapping using MapStruct
  • How to I find the original row index of a table in a google visualization if I have a filtered rows view
  • Ribbon icon doesn't show up in Word Online
  • Fitting user defined function with MPFIT in IDL
  • yii2 user CRUD create or update with password
  • Does Perl 6 performance suffer by using rationals for decimal numbers
  • How to get Y value at a given X value of a trendline
  • ElastAlert flatline not finding results
  • CSS not extracted for common chunk with extract-text-webpack-plugin
  • Adding element to nested vector
  • How can I trigger an action after updating a Podio Category on zapier?
  • Ninject.MVC5 Release Scope Never Called - OutOfMemoryException
  • Grok custom time format
  • How can I avoid Same Origin Policy exception when using AWS API Gateway and CloudFront
  • How to test ActionCable with Capybara and poltergeist inside Docker?
  • opendaylight: how to include a library jar file?
  • OpenThread using Nest Learning Thermostat
  • In Coq, how to remove a defined variable from the namespace?
  • Adobe DTM Mobile Tracking Rules
  • Accessing Vuex submodules inner state with the $store object
  • Include one widget instead of excluding all others
  • Create folder temp in mac using lotuscript
  • RSU placement in veins/SUMO
  • Exclamation Unary operator stopped working on bindings
  • RxJs how to merge two overlapping observable into one
  • How to add Nuget Package Source at runtime?
  • Absolute positioning a FlatList item react-native
  • Python, using variables in pymodbus.utilities.computeCRC
  • Akamai CDN - Whitelist service by Request header or User agent
  • UIWebView/WKWebView crash on iOS11 (ran out of executable memory)
  • Is ZonePlayerId capability still working?
  • Testing polynomial definition (from natural numbers to integers)
  • Wakanda 2.x cannot set certain tables' scope to publicOnServer
  • Call task from another Verilog module
  • Perl 6 transforms combined graphemes?
  • How to get automake to set libdir to /usr/lib64 on dual-arch Linux platforms
  • Restore RSA private key by modulus, public and private exponents using Java Security
  • Visual Studio 2017 Reset Settings
  • SonarQube 6.5 - Not able to trigger TFS Build Definition
  • Composing tweet in Twitterkit since Xcode 9 with Swift 4 & IOS 11
  • Custom Bing Map Type Issue
  • How to update MvvmCross?
  • pageFunction in Puppeteer returns empty object
  • PyCharm Run --- why does it sometimes display a traceback and error and sometimes not?
  • Yii2, optional parameter in the rounte
  • Hive and Pig on top of same dataset
  • SCM_REPOSITORY_PATH being ignored on Azure web app
  • Pentaho Flow Input->Output->Input not working
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org