/retool-tutorials

How to use custom widgets in Retool?

Learn how to enhance Retool apps with custom widgets using JavaScript, HTML, and CSS. Follow this step-by-step guide for a seamless integration.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web or mobile app? RapidDev builds Retool apps with your growth in mind.

Book a free No-Code consultation

How to use custom widgets in Retool?

 

Using Custom Widgets in Retool

 

Custom widgets in Retool allow you to extend the platform's capabilities by incorporating custom-written JavaScript/HTML/CSS components. This guide provides a comprehensive step-by-step approach to leveraging custom widgets in Retool effectively.

 

Prerequisites

 

  • Active Retool account with at least one application created.
  • Basic knowledge of web development using JavaScript, HTML, and CSS.
  • Understanding of Retool's UI elements and data fetching capabilities.

 

Accessing the Custom Widget Module

 

  • Log in to your Retool account and navigate to the application dashboard.
  • Select the application where you want to add a custom widget, and click on it to open the editor.
  • Within the editor, locate the component panel on the right-hand side.
  • Find and drag the Custom component into your canvas. This component allows you to write custom code for your widget.

 

Writing Custom Widget Code

 

  • Click on the custom widget to open the configuration panel.
  • Navigate to the Code tab within the panel, where you can start writing your custom JavaScript/HTML/CSS.
  • Within the code editor, specify the HTML structure you want to render using document templates; for example:
    <pre>
    

    <div>
    <h2>Custom Weather Widget</h2>
    <div id="weather-info"></div>
    </div>

  • Integrate JavaScript under the JavaScript section to handle interactivity or data fetching. Here’s an example to fetch and display weather data:
    <pre>
    const weatherInfoDiv = document.getElementById('weather-info');
    fetch('https://api.weatherapi.com/v1/current.json?key=YOURAPIKEY&q=New York')
      .then(response =&gt; response.json())
      .then(data =&gt; {
          weatherInfoDiv.innerHTML = Temperature: ${data.current.temp_f}°F;
      })
      .catch(error =&gt; console.error('Error fetching weather data:', error));
    </pre>
    

 

Styling Your Custom Widget

 

  • Go to the CSS section in the code editor to write custom styles for your widget.
  • Input corresponding CSS to enhance the widget's design. For instance:
    <pre>
    h2 {
      color: #333;
      font-size: 18px;
    }
    #weather-info {
      background-color: #f7f7f7;
      padding: 10px;
      border-radius: 5px;
    }
    </pre>
    

 

Connecting Custom Widgets to Retool Data Sources

 

  • Use Retool’s JavaScript to query data from other components or Retool queries directly within your widget code.
  • For example, to use data from a Retool query named weatherQuery, you can do something like this:
    <pre>
    const weatherData = {{ weatherQuery.data }};
    document.getElementById('weather-info').innerText = weatherData ? weatherData.temp : 'No Data';
    </pre>
    

 

Debugging and Testing Your Custom Widget

 

  • Use the Preview option in Retool to see your widget in action and detect any runtime errors.
  • Utilize browser developer tools, such as console.log() statements, to debug JavaScript code.
  • Retool’s debugging console can be used to display logs for easier troubleshooting.

 

Final Adjustments and Deployment

 

  • After verifying that the custom widget performs as expected, return to the editor and refine styles and scripts accordingly.
  • From the dashboard, deploy your Retool application to production to make the new widget available for end users.
  • Ensure all permissions and data requirements are correctly configured for deployment.

 

By following these steps, you will be able to utilize custom widgets in Retool to enhance your applications with bespoke functionalities, thereby providing a tailored user experience.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022