I am seeing some weird behavior in conditionalPanel and I am not sure why. It happens when I assign two sidebar input IDs for conditionalPanel, one for menuItem, one for tabPanel, then conditionalPanel starts to selectively ignoring the conditions I set in some cases.

Here is an example : Link for the example shinydashboard.

reactiveValues() in R Shiny - Example 1 - A counter

I am trying to have the default selection of comparison date picker change based on the menuItems and tabs selected. In all of the cases, there should only be one comparison date picker, based on the conditions I set for conditionalPanel. However, in menu3, comparison date picker for menu2 also appears depend on which tab is last selected in menu2, the extra date picker will be either last year or last week ; in menu1, if tab2 in menu2 is selected before clicking on menu1, an additional comparison date picker will also be shown.

Here is the app. I see the problem now! Thank you so much!!! Hi, I am seeing some weird behavior in conditionalPanel and I am not sure why. Here is an example : Link for the example shinydashboard I am trying to have the default selection of comparison date picker change based on the menuItems and tabs selected.

Should only see one comparison date picker. Hi huiyan I'd update the condition to be more restrictive. Maybe something like the conditions below for each of the condition panels input.GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account. Following up on my own Stack Overflow question.

This article on building a dynamic UI suggests that one way to pass values to a conditionalPanel is to use an output variable. The example given below shows this only works if that variable is also rendered elsewhere in the UI - the JavaScript does not seem to have access to the value if it is not also rendered. The example given in the SO question shows the use-case of encapsulating a selectize input within a module, but here is a more minimal example:.

And if we don't calculate them, you can't use them in conditions. You can change this behavior this by setting an output to calculate every time, you can use this in your server. R replace outputId with the corresponding value :. We use optional third-party analytics cookies to understand how you use GitHub. Learn more. You can always update your selection by clicking Cookie Preferences at the bottom of the page.

Subscribe to RSS

For more information, see our Privacy Statement. We use essential cookies to perform essential website functions, e. We use analytics cookies to understand how you use our websites so we can make them better, e. Skip to content. Dismiss Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Sign up. New issue. Jump to bottom. Copy link Quote reply. Ahh yes that solves it, thank you, Joe.

I updated the SO question with this solution. Sign up for free to join this conversation on GitHub.Shiny is a great way of letting users interact with their own data and the data science products that we provide. Shiny was designed to be reactive, so why limit this to only the server-side of your app? Introducing dynamic UI elements to your apps will help you reduce visual clutter, make for cleaner code and enhance the overall feel of your applications.

I have previously discussed the advantages of using renderUI in combination with lapply and do. Building onto this I would like to expand our toolbox for reactive UI design with a few more options.

One way to do this would be to add a static textInput or similar to the app. A much more elegant solution would be to conditionally render the second input to only appear if the proper option had been selected. The image below shows how this would look in practice. There are multiple ways of going about this in Shiny.

You may have seen one of these before:. These errors usually disappear once you have assigned a value to the needed inputs. This is achieved by using renderUI and req in combination as shown in the following example:. Within req the condition to be met is specified and the rest of the code inside the reactive environment created by renderUI is only executed if that condition is met.

Out of all the tools available for reactive UI design this is probably the most widely used. The results obtained with conditionalPanel are quite similar to what req allowed us to do in the example above, but there are a few key differences.

But wait, you might ask, how can Shiny evaluate any conditions in the UI-side of the app? Well yes, that is true if the expression is written in R. To get around this, conditionalPanel relies on JavaScript to evaluate its conditions. After stating the condition in JS we can add any given UI-elements to our conditionalPanel as shown below:. Rewriting the app to include conditionalPanel instead of req yields a script that looks something like this:. With these two simple examples we have demonstrated multiple ways of letting your displayed UI elements react to how a user interacts with your app — both on the server, as well as the UI side of the application.

In order to keep things simple I have used a basic textAreaInput for this demonstration, but both renderUI and conditionalPanel can hold so much more than just a simple input element. So get creative and utilize these tools, maybe even in combination with the functions from part 1 of this seriesto make your apps even shinier! If you have questions or suggestions, please write us an e-mail addressed to blog at statworx.

A possible solution: req What req is usually used for req is a function from the Shiny package whose purpose is to check whether certain requirements are met before proceeding with your calculations inside a reactive environment. You may have seen one of these before: These errors usually disappear once you have assigned a value to the needed inputs.

The popular choice: conditionalPanel Out of all the tools available for reactive UI design this is probably the most widely used.

How does this differ from req? Sign Up Now! Data Science.Creates a panel that is visible or not, depending on the value of a JavaScript expression. A JavaScript expression that will be evaluated repeatedly to determine whether the panel should be displayed. In the JS expression, you can refer to input and output JavaScript objects that contain the current values of input and output.

For example, if you have an input with an id of foothen you can use input. You are not recommended to use special JavaScript characters such as a period. For more information on customizing the embed code, read Embedding Snippets. Functions Source code Man pages R Description Creates a panel that is visible or not, depending on the value of a JavaScript expression. Usage 1. R Package Documentation rdrr.

We want your feedback! Note that we can't provide technical support on individual packages. You should contact the package authors for that. Tweet to rdrrHQ. GitHub issue tracker. Personal blog. What can we improve?

The page or its content looks wrong. I can't find what I'm looking for.

Dynamic UI Elements in Shiny – Part 2

I have a suggestion. Extra info optional. Embedding an R snippet on your website. Add the following code to your website.Tag: rshiny. What I really want to do is pass a numeric output condition for generating a conditional panel. I can't seem to render an output as numeric though. My work around was to generate a reactive using the numeric condition of interest and pass that to the conditional panel as text.

However, I'm struggling with this as well. At first it seems that Shiny needs to have the value displayed to use it in a condition, but this is not actually true:. Even if you add this line in your server function, you need another change: the value of big needs to be calculated, so this:. You can try library data.

r shiny conditionalpanel multiple conditions

It's easier to think of it in terms of the two exposures that aren't used, rather than the five that are. As per? R prefers to use i rather than j. Aslo note that complex is different than as. Your intuition is correct. The problem is that you pass the condition as a string and not as a real condition, so R can't evaluate it when you want it to. Change the panel. For some reason the top and bottom margins need to be negative to line up perfectly.

Here is the result You are using it to copy a list. They are still referenced by Here's a solution for extracting the article lines only. Turned out much more complex and cryptic than I'd been hoping, but I'm pretty sure it works.

Also, thanks to akrun for the test data. You can create a similar plot in ggplot, but you will need to do some reshaping of the data first. Do not use the dates in your plot, use a numeric sequence as x axis. You can use the dates as labels. You can put your records into a data.You can report issue about the content on this page here Want to share your content on R-bloggers? Shiny is a great way of letting users interact with their own data and the data science products that we provide.

Shiny was designed to be reactive, so why limit this to only the server-side of your app? Introducing dynamic UI elements to your apps will help you reduce visual clutter, make for cleaner code and enhance the overall feel of your applications. I have previously discussed the advantages of using renderUI in combination with lapply and do. Building onto this I would like to expand our toolbox for reactive UI design with a few more options.

One way to do this would be to add a static textInput or similar to the app. A much more elegant solution would be to conditionally render the second input to only appear if the proper option had been selected. The image below shows how this would look in practice. There are multiple ways of going about this in Shiny. You may have seen one of these before:.

These errors usually disappear once you have assigned a value to the needed inputs. This is achieved by using renderUI and req in combination as shown in the following example:.

r shiny conditionalpanel multiple conditions

Within req the condition to be met is specified and the rest of the code inside the reactive environment created by renderUI is only executed if that condition is met. Out of all the tools available for reactive UI design this is probably the most widely used. The results obtained with conditionalPanel are quite similar to what req allowed us to do in the example above, but there are a few key differences. But wait, you might ask, how can Shiny evaluate any conditions in the UI-side of the app?

Well yes, that is true if the expression is written in R. To get around this, conditionalPanel relies on JavaScript to evaluate its conditions.

After stating the condition in JS we can add any given UI-elements to our conditionalPanel as shown below:. Rewriting the app to include conditionalPanel instead of req yields a script that looks something like this:. With these two simple examples we have demonstrated multiple ways of letting your displayed UI elements react to how a user interacts with your app — both on the server, as well as the UI side of the application.Creates a panel that is visible or not, depending on the value of a JavaScript expression.

In the JS expression, you can refer to input and output JavaScript objects that contain the current values of input and output. For example, if you have an input with an id of foothen you can use input. You are not recommended to use special JavaScript characters such as a period.

Shiny from. Conditional Panel conditionalPanel conditionArguments condition A JavaScript expression that will be evaluated repeatedly to determine whether the panel should be displayed. Elements to include in the panel.

Description Creates a panel that is visible or not, depending on the value of a JavaScript expression. Details In the JS expression, you can refer to input and output JavaScript objects that contain the current values of input and output.

r shiny conditionalpanel multiple conditions

Note You are not recommended to use special JavaScript characters such as a period. A JavaScript expression that will be evaluated repeatedly to determine whether the panel should be displayed.


Replies to “R shiny conditionalpanel multiple conditions”

Leave a Reply

Your email address will not be published. Required fields are marked *