Debug, troubleshoot, & help
Common issues
Before jumping into general debugging techniques, lets cover some common issues that you may encounter when developing Shiny applications, and explain why they happen.
Missing output
Sometimes, confusingly, output won’t appear at all. This most commonly happens when an output reads a non-existent input, for example:
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 120
from shiny.express import input, render, ui
ui.input_slider("val", "Slider value", min=0, max=10, value=5)
# Nothing renders because input.wrong_id() doesn't exist!
@render.text
def slider_val():
return f"Slider value: {input.wrong_id()}"
This happens because, if a non-existent input is read, a SilentException
is raised. That behavior is useful for events and dynamic ui, but it can be confusing when you mistype an input id.
Output errors
When an error occurs inside a render
function, the relevant error message is displayed in red font where the output would normally be located, for example:
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 120
from shiny.express import render
@render.text
def good():
return "This output is fine, but the next one is not."
@render.text
def bad():
return str(a_missing_variable)
The error displayed in the app is only the final part of the stack trace, but the full trace can be read in the console where you used shiny run
.
When Shiny apps are deployed, error messages are sanitized to the eliminate the possibility of leaking sensitive information. To unsanitize error messages, you’ll need to set sanitize_errors=True
in the App
constructor (of a Shiny core app).
Debugging
VS Code debugger
The VS Code debugger is a powerful tool for debugging Python code.
Breakpoints
A breakpoint()
is a point in your code where you want to pause execution and inspect the program state via the Python debugger (pdb).
@render.text
def bad():
breakpoint()
return str(a_missing_variable)
When a breakpoint is hit, the program will pause and you can them send commands like break
(i.e., exit) and continue
to the debugger. Ctrl+D
will also exit the debugger.
Print statements
A quick and simple way to debug Shiny applications is to add print()
statements. This lets you see the value of different variables, and how they change when you toggle different inputs.
If your Shiny application is running with Shinylive (Python in the browser), and there is not a visible Python console, then error messages will show up in your browser’s JavaScript console.
Shiny debug mode
An advanced option for debugging apps is using the App(..., debug=True)
argument. This is not super useful in general, as it requires some knowledge of Shiny’s internals.
In debug mode, Shiny applications log in the console all of the messages that the server sends and receive from browser sessions. This is the raw data behind how changes to inputs cause calculations on the server, and how messages from the server cause the client’s browser to update (e.g. a plot).
Here is a short log example.
SEND: {"busy": "busy"}
SEND: {"recalculating": {"name": "my_cool_output", "status": "recalculating"}}
SEND: {"recalculating": {"name": "my_cool_output", "status": "recalculated"}}
SEND: {"busy": "idle"}
SEND: {"values": {}, "inputMessages": [], "errors": {}}
Note also that Shiny applications use Python’s asyncio under the hood, so it may be useful to set asyncio’s debug mode.
Get Help
Shiny
The first place to look for help with Shiny is Posit Community, which is a warm and welcoming place to ask any questions you might have about Shiny (as well as tidyverse and all things Posit). The web site is running Discourse, which is an excellent community discussion platform. Our developers monitor Posit Community and answer questions periodically.
Shiny users (and the Shiny team!) regularly talk on Shiny’s Discord server. Discord has more of a chat interface than Posit Community, and is not indexed by search engines. It’s a great forum for casual conversations or networking with other Shiny developers.
You can also check the “shiny+python” tag on Stack Overflow for existing answers, or post your own question. (Keep in mind that general Shiny for R answers may also point you in the right direction.) Note that questions posted on Stack Overflow are not closely monitored by our developers.
shinyapps.io
For documentation and instructions on how to use shinyapps.io, see the shinyapps.io user guide.
The best place to get community support for shinyapps.io is the shinyapps.io category on Posit Community. If you’re having difficulties with shinyapps.io, feel free to ask questions there. Another option is to file an issue in the rsconnect-python package repo.
Customers with Starter, Basic, Standard or Pro subscriptions can get direct access to our support engineers by opening a case on the Posit Support site. Questions are answered from 9AM - 5PM(EST) Monday - Friday.
Posit Connect and Shiny Server Pro
Customers with Posit Connect or Shiny Server Pro subscriptions can contact our dedicated support team for our commercial offerings.
Sales
For sales questions, please email sales@posit.co.