English 中文(简体)
“因果彩色错误”在使用多种彩色盒作为光彩选择的密封清单时 s块功能投入
原标题:‘Invalid color name error’ when using multiple color palette as a nested list in shiny selectInput for sf plot function
  • 时间:2023-07-01 02:44:04
  •  标签:
  • r
  • shiny
  • sf

有些人可以帮助我理解以下法典有什么错误。 我想利用两类彩色棕榈树,即单体和多壳体,在雕塑功能中进行大谈。 提前感谢。

shinyApp(
  ui = fluidPage(
    selectInput(inputId = "pal", label = "Select a sequential color palette", 
                choices = list(
                  
                  `single hue` = list(
                    `Grays` = c("#F9F9F9", "#969696", "#1B1B1B"),
                    `Reds 3` = c("#F6F6F6", "#FF7078", "#69000C")),
                  
                  `multi hue` = list(
                    `Dark mint` = c("#D1FBD4", "#579C97", "#0E3F5C"),
                    `YlOrRd`  = c("#FFFFC8", "#F39300", "#7D0025"))
                )
    ),
    plotOutput("plot")
  ),
  
  server = function(input, output) {
    dat1 <- rnaturalearth::ne_countries(returnclass = "sf", scale = 110)
    
    output$plot <- renderPlot({
      plot(dat1["gdp_md_est"],
           key.pos = 4, 
           axes = FALSE,
           pal = colorRampPalette(input$pal),
           key.width = lcm(1.3), key.length = 0.75
      )
    })
  }
)
问题回答

您有3个等级深厚的标码<>电子输入/代码>,难以解释,也难以混淆。 我实际上建议将其分为两条<代码>电子数据输入/编码>。 第二项是根据首项选择更新的。

library(shiny)

pallette <- list(`single hue` = list(
  `Grays` = c("#F9F9F9", "#969696", "#1B1B1B"),
  `Reds 3` = c("#F6F6F6", "#FF7078", "#69000C")),

`multi hue` = list(
  `Dark mint` = c("#D1FBD4", "#579C97", "#0E3F5C"),
  `YlOrRd`  = c("#FFFFC8", "#F39300", "#7D0025"))
)

shinyApp(
  ui = fluidPage(
    selectInput("category", "Select Category : ", c("single hue", "multi hue")), 
    selectInput("pal", "Select a sequential color palette", ""),
    plotOutput("plot")
  ),
  
  server = function(input, output, session) {
    dat1 <- rnaturalearth::ne_countries(returnclass = "sf", scale = 110)
    
    observe({
      updateSelectInput(session, "pal", choices = pallette[[input$category]])  
    })
    
    output$plot <- renderPlot({
      req(input$pal)
      plot(dat1["gdp_md_est"],
           key.pos = 4, 
           axes = FALSE,
           pal = colorRampPalette(input$pal),
           key.width = lcm(1.3), key.length = 0.75
      )
    })
  }
)

“enterography





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签