簡體   English   中英

在 R 中使用 numericRangeInput 在 ggplot2 中設置 xlim

[英]set xlim in ggplot2 using numericRangeInput in R shiny

我想使用 numericrangeInput 控制 xlim。 初始值設置為 c(NA,NA)。

如果我嘗試更改比例最小值和最大值,並且在更新其中一個值之前會引發錯誤Missing values cannot be used where TRUE/FALSE values are required

任何修復此錯誤的建議。

下面是代碼

      library(shiny)
      library(tidyverse)

      data <- faithful %>% mutate(eruptionTime=lubridate::now() + lubridate::dhours(cumsum(waiting)))

      ui <- fluidPage(
             numericRangeInput(inputId = "noui1", label = "Numeric Range Input:",
             value = c(NA, NA)
             ),  
            plotOutput("plot9")
            )

      server <- function(input, output) {


           output$plot9 <- renderPlot({

           print(paste("What is the condition",!anyNA(input$noui1))) 
   
           iris %>%ggplot() + geom_point(aes(x=Sepal.Length, y=Petal.Length)) +
           coord_cartesian(xlim=input$noui1)

          })
          }

     shinyApp(ui = ui, server = server)

只有在numericRangeInput輸入兩個數字后,才能更新繪圖。

試試這個代碼 -

library(shiny)
library(tidyverse)

data <- faithful %>% mutate(eruptionTime=lubridate::now() + lubridate::dhours(cumsum(waiting)))

ui <- fluidPage(
  numericRangeInput(inputId = "noui1", label = "Numeric Range Input:",
                    value = c(NA, NA)
  ),  
  plotOutput("plot9")
)

server <- function(input, output) {
  
  
  output$plot9 <- renderPlot({
    plot <- iris %>%ggplot() + geom_point(aes(x=Sepal.Length, y=Petal.Length))
    
    if(length(input$noui1) == 2)
      plot <- plot + coord_cartesian(xlim=input$noui1)
    plot
  })
}

shinyApp(ui = ui, server = server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM