Glistening: sending reactiveValues to conditionalPanel

Is it possible to pass a reactiveValues to the condition of a conditionalPanel? If so, what is the correct method?

Below is my attempt in the UI.R file for the conditionalPanel:

conditionalPanel(condition = "values.cond == 0", etc.

I have defined values$cond in server.R like this:

values <- reactiveValues(cond = 0)

I have also experimented with other options such as "values.cond == true", but I have not been successful.

library("shiny")
runGist("https://gist.github.com/anonymous/8281021")

Take a look at the code here:

https://gist.github.com/anonymous/8281021

Answer №1

Highlighted by @jdharrison, the issue at hand is having reactive values or other data on the server side while the conditional panel operates with a JS condition and HTML on the client side. To dynamically update the JS condition based on a server-side calculated value, transferring the data from the server to the client is necessary. One possible solution involves leveraging an undocumented shiny feature for custom data transfer. Detailed steps on how to achieve this can be found in my blog post:

An alternative approach could entail utilizing a JS function to update the conditional panel condition after the data has been successfully transmitted. Essentially, this would involve replacing the data-display-if attribute of the conditionalPanel output with desired values.

Another suggestion: In scenarios where the UI heavily relies on server-side calculations, creating (sidebar) content dynamically using renderUI might be worth considering.

UPDATE: Additionally, as mentioned by @jdharrison in a following comment.

Answer №2

You have the option to achieve this by rendering text.

UI:

shinyUI(
  fluidPage(
    # Setting the title of the application
    titlePanel("Test"),

    sidebarLayout(
      sidebarPanel(
        actionButton("ShowCond", "Show Conditional Panel"),
        conditionalPanel(
          condition = "output.test=='5'",
          actionButton("CheckFile", "Check file")
        )
      ),
      mainPanel(
        verbatimTextOutput("test")
      )
    )
  )
)

Server:

shinyServer(function(input, output, session) {
  var <- eventReactive(input$ShowCond, {
    5
  })

  output$test <- renderText({
    var()
  })
})

The important point to note is that without including the verbatimTextOutput, it will not function as expected. It must be incorporated somewhere within your UI section. Nevertheless, you can repurpose it as a message.

EDIT:

It is also achievable without using verbatimtext. By default, Shiny halts all outputs when they are not visible. However, this behavior can be altered by specifying the following option for a particular output variable:

outputOptions(output, "test", suspendWhenHidden=FALSE)

In such cases, there is no necessity for utilizing verbatimtext (and the related rendertext).

Source:

Answer №3

After reviewing the information above, I came up with a solution by utilizing both a reactiveVal (for other parts of your application) and outputting it as recommended.

your_reactive <- reactiveVal(NULL)

# Read input csv file
output$your_output <- eventReactive(TRUE, {
 
  out <- ""
      
  your_reactive(out) # update server side reactive
  
  return(out)
  
  })

# Ensure visibility on client side
outputOptions(output, "your_output", suspendWhenHidden = FALSE)

You can now access output.your_output in your user interface.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging AngularJS html5mode in conjunction with express.js

Client-side: when("/page/:id", { templateUrl: "partials/note-tpl.html", controller : "AppPageController" }); $locationProvider.html5Mode( true ); Html: <a ng-href="/page/{{Page._id}}">{{Page.name}}</a> Server-side: app.use("/pag ...

I am seeing the object in req.body displayed in reverse order within my Node.js and Express backend application

I encountered an issue while developing a To-do list web application using the MERN stack with Redux. The problem arises when I try to send post data to the backend. In my form, the textfield area is named 'task' (e.g., ) and I input 'jonas& ...

The server was unable to start because NPM was unable to navigate to the wrong directory and locate the package.json file

I recently used vue create to start a project and everything went smoothly. However, when I tried to run npm run serve, I encountered an issue where node couldn't locate the package.json file that was generated during the project creation process. Th ...

Styled-components causing issues with conditional rendering

Within my React component, I have multiple properties and I want styles to only apply if a property has a value. I attempted the following code: export const Text = ({text, color, size, fontFamily}) => { const StyledParagraph = styled.p` m ...

D3: Ensuring Map is Scaled Correctly and Oriented Correctly

I am attempting to integrate a map into a website using D3 and topoJSON that resembles the following: https://i.sstatic.net/1brVx.png However, when I create the map with D3/topoJSON, it shows up small and inverted. https://i.sstatic.net/LgQBd.png Even ...

Like button for Facebook located at the bottom of a static webpage

I am facing an issue with my web application where it does not scroll properly, especially when there is a Facebook button at the bottom. The behavior in Chrome and Firefox is inconsistent and causing some trouble. In Chrome, the div repositions correctly ...

Utilize moment.js to convert an epoch date into a designated time zone

I've spent countless hours searching for a resolution to the issue with moment.js and its inability to accurately display the correct date for a given local time zone. Let me explain my predicament: The flight API I'm utilizing provides me w ...

javascript mysql and php clash when it comes to loading

I am encountering an issue where I cannot fetch data from my phpMyAdmin database using php code when loading the map api that utilizes javascript. Currently, only the map javascript is being loaded. I have valuable data stored in my database and any assis ...

Displaying a component in a router view based on specific conditions

Currently, I am delving into the world of Vue3 as a newcomer to VueJS. In my project, there is an App.vue component that serves as the default for rendering all components. However, I have a Login.vue component and I want to exclude the section when rende ...

Creating a line between two points in raphael

Hello there, I'm looking to create a line between two points in Raphael. Could you please provide me with some examples or guidance on how to achieve this? Thanks a lot!) ...

A Node.js feature that enables atomic file replacement, triggering watchers only once

I have a unique scenario where I need to handle two types of processes. One process is responsible for writing a file, while the other processes are required to read it whenever there is a change. In my research, I came across fs.watch as a solution to ke ...

Ways to split up array objects in an axios GET request

Hello, I recently implemented an AXIOS GET request that returns an array of objects. However, the current example I am using retrieves the entire array at once, and I need to separate the objects so that I can work with them individually. class CryptoAP ...

Sending a PHP variable to a modal using jQuery Ajax

I've encountered an issue with my jQuery ajax script. I'm struggling to pass a variable to the modal despite spending all weekend trying to debug it. Here is the link used to call the modal and the ID I want to pass: echo '<img src="./i ...

What is the most effective way to loop through HTML elements using wildcards in Puppeteer to extract innerText?

Seeking insights for educational purposes, I am in search of the reviews on this specific page . Each page contains 10 reviews, and I have a set of HTML selectors (previously used code) to extract these comments: #review_593124597 > div:nth-child(1) &g ...

Saving the content of a div as a PDF

There are several aspects to consider when it comes to this question, but I'm having trouble finding the information I need. Hopefully someone can provide an answer. Essentially, what I want to achieve is: Imagine a div that is 400 X 400 px in size. ...

The function JSON.parse(data) may result in an undefined value being returned

data = { "users": [ [{ "value": "01", "text": "ABC XYZ" }], [{ "value": "02", "text": "XYZ ABC" }] ] } var jsonData = JSON.parse(data); for (var i = 0; i < jsonData.users.length; i++) { var userlist = json ...

Looking to display all items once the page has finished loading

I am experiencing a minor issue. Every time I access my store page where all products are listed, I have to click on the size filter to load the products. This is not ideal as I want all products to be displayed automatically when the page loads. What modi ...

Tips for concealing a dynamic DOM element using JQuery after it has been generated

My current project involves creating a form that allows users to dynamically add text fields by clicking on an "add option" button. Additionally, they should be able to remove added fields with a "remove option" link that is generated by JQuery along with ...

Enabling and disabling links in a Bootstrap dropdown menu with dynamic functionality on click

One interesting feature of bootstrap is that it allows users to disable links within its dropdown menu component by simply adding a class="disabled" into the corresponding <li> tag. I am looking to create some Javascript code so that when a user sel ...

When clicking on a link in React, initiate the download of a text file

Usually, I can use the following line to initiate the download of files: <a href={require("../path/to/file.pdf")} download="myFile">Download file</a> However, when dealing with plain text files like a .txt file, clicking on ...