如何在.Riny中简洁地使用updateselection()



我在RShiny中的脚本有问题。事实上,这个脚本是有效的,但我有这个错误/警告:

美学必须是长度1或与数据相同(1(:x,填充

您可以在[github]上访问我的脚本(https://github.com/vladamihaesei/Rshiny_stripes_temperatures)

library(shiny)
library(shinythemes)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
temp <- read.csv("Temperature_1961-2010.csv", stringsAsFactors = FALSE)
col_strip <- brewer.pal(11, "RdBu")
ui <- fluidPage(theme = shinytheme("darkly"),
titlePanel("Temperature of Romania 1961-2010"),
sidebarLayout(
sidebarPanel(
selectInput("RegiuneInput", "Regiune",
choices = unique(temp$CMR)),
selectInput("judetInput", "Judet",
choices = unique(temp$NUME))
),
mainPanel(plotOutput("coolplot"))
)
)
server <- function(input, output, session) {
observeEvent(input$RegiuneInput,
updateSelectInput(session, "judetInput", "Judet",
choices = unique(temp$NUME[temp$CMR==input$RegiuneInput])))
output$coolplot <- renderPlot({
filtered1 <- temp  %>%
filter(CMR == isolate(input$RegiuneInput),
NUME == input$judetInput)
ggplot(filtered1,
aes(x = Data, y = 1, fill = Temp))+
geom_tile() +
scale_fill_gradientn(colors = rev(col_strip)) +
guides(fill = guide_colorbar(barwidth = 1)) +
theme_void()
})
}
shinyApp(ui = ui, server = server)

最新更新