私の仕事ではいくつかの問題が発生しています。問題を明確にするために、私はダイヤモンドデータを例として使用しています。は、光沢のあるアプリケーションのselectinputウィジェットにオプションNULLを含む
私は関数sca.plotを作成しました。引数color.by = NULLの場合は、散布図を作成し、すべての点を赤色にします。 color.byが因子変数の場合は、変数で散布図とカラーポイントを作成します。
私のインタラクティブな散布図を光沢のあるものにするのが私の質問です。 selectinputウィジェットにNULLオプションを含めるにはどうしたらいいですか?
selectinputの選択肢にNULLを含めると、エラーが発生します。それを理解できませんでした....
ありがとうございます。
以下私のコードです:ここでは
library(ggplot2)
sca.plot <- function (color.by=NULL) {
if (is.null(color.by)) {
diamonds %>% ggplot(aes(x, y))+
geom_point (color='red')
} else {
color.by = sym(color.by)
diamonds %>% ggplot(aes_(~x, ~y, color=color.by))+
geom_point()
}
}
sca.plot(color.by='clarity')
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput('colorby', label = h5(strong('Color By')),
choices = list('clarity', 'cut'),
selected = NULL)
),
mainPanel(
plotOutput('plot')
)
)
)
server <- function(input, output) {
output$plot <- renderPlot ({
sca.plot(color.by=input$colorby)
})
}
runApp(shinyApp(ui, server))
[This](https://github.com/rstudio/shiny/issues/559)のリンクが役立ちます。 – SBista
@SBistaこのリンクは私の質問に答えます。ありがとう! – zesla