You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法运行含plotly图表的flexdashboard示例代码,求助解决报错问题

Troubleshooting Flexdashboard + Plotly Render Errors

Hey there, let's work through this issue you're having with flexdashboard and plotly charts. Even though you aren't using Shiny or setting a working directory, here are some actionable steps to diagnose and fix the problem:

  • Update your dependency packages first
    Version mismatches between flexdashboard, plotly, and ggplot2 are super common culprits here. Run this command to refresh all relevant packages, then restart your R session entirely before trying again:

    update.packages(c("flexdashboard", "plotly", "ggplot2"), dependencies = TRUE)
    
  • Simplify your code to isolate the issue
    Strip down your dashboard to the absolute minimum to test if the core functionality works. For example, use this bare-bones code:

    ---
    title: "Minimal Test Dashboard"
    output: flexdashboard::flex_dashboard
    ---
    
    ```{r}
    library(ggplot2)
    library(plotly)
    
    # Basic ggplot converted to plotly
    p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
    ggplotly(p)
    
    If this runs without errors, gradually add back parts of your original code until the error reappears—this will help you pinpoint exactly which chart or chunk is causing the problem.
    
    
  • Eliminate global environment conflicts
    Sometimes stray variables or conflicting packages loaded in your global environment can break dashboard rendering. Before running your dashboard, clear the environment and only load the packages you need:

    rm(list = ls(all.names = TRUE)) # Clear all objects
    gc() # Free up memory
    library(flexdashboard)
    library(ggplot2)
    library(plotly)
    
  • Dig into the exact error details
    Generic errors don't tell us much—if you can share the full error message (both R console output and any browser console errors, accessible via F12 > Console tab), that's gold. For example:

    • R-side errors might point to missing data, invalid syntax, or package function conflicts.
    • Browser JS errors could indicate issues with plotly's JavaScript rendering in the dashboard framework.
  • Test plotly functionality outside flexdashboard
    Verify that your ggplotly charts work on their own first. Save a single chart as an HTML widget:

    htmlwidgets::saveWidget(ggplotly(p), "test_plot.html")
    

    If this file opens and displays correctly, the issue is likely specific to how flexdashboard is rendering the widget—not the plotly chart itself. Try removing any custom dashboard themes or layout settings to see if that fixes it.

内容的提问来源于stack exchange,提问作者Sean O'Brien

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:26:38