我想在我的Shiny应用程序中绘制一个标绘的3D图形,但仅限具有输入范围滑块范围内的值的数据。不过,我想阻止密谋当有滑块的范围内,没有价值观 - 目前这会导致以下错误,当没有输入:闪亮 - 如果没有使用滑块选择数据,如何防止绘图
Warning: Error in UseMethod: no applicable method for 'plotly_build' applied
to an object of class "NULL"
或示例代码:
Error in : length(Lab) == 3L is not TRUE
这是有一个类似的错误作为原问题的一个示例代码:
library(shiny)
library(plotly)
d = diamonds[1:100,]
ui = fluidPage(
headerPanel("Data"),
sliderInput(inputId="slider", label = "Choose a range", value =c(0,max(d$price)),
min = 0,max = max(d$price)),
# saves space for the plot in the user interface. Id allows communication
plotlyOutput(outputId="trendPlot", width="100%", height=800)
)
server = function(input, output)
{
NROF = reactiveValues(test = 1)
output$trendPlot= renderPlotly({
d_sub=d[d$price >= input$slider[1] & d$price <= input$slider[2],]
NROF = nrow(d)
if(NROF != 0)
{
plot_ly(d_sub, x=d_sub$cut, y=d_sub$color, z=factor(d_sub$color),
type='scatter3d', mode='markers',
sizemode='diameter', size=d_sub$price, color=d_sub$price,colors = 'Set1')
}
})
}
shinyApp(ui=ui, server=server)
解决办法:我一直在使用抗值犯了一个错误 - 它应该是NROF $ TEST
请编辑和proviing重复的例子,简化你的问题。例如提供完全可执行的闪亮代码(服务器和用户界面),只包括您的问题。 – Jimbou
好的,错误/警告来自plotly函数的颜色参数。如果使用d $ color,它会渲染它(尽管在观察颜色时过滤时会使用不正确的颜色),所以问题保持不变。 –