如何在Shiny-折线图R中进行数据集的反应函数

问题描述 投票:0回答:1

如何在Shiny-折线图中进行数据集的反应函数特别是不了解如何将数据集应用于reactive()函数以响应所选输入]

# sample data
df <- economics %>%
  select(date, psavert, uempmed) %>%
  gather(key = "variable", value = "value", -date) %>%
  as.data.table()

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Football Analysis"),

  sidebarLayout(
    sidebarPanel(
      selectizeInput("variable_names", "Names of Variable", choices = unique(df$variable), selected = unique(df$variable)[1])
    ),

    mainPanel(
      highchartOutput("plot")
    )
  )
)

server <- function(input, output) {

  reactivedf <- reactive({ df[variable == input$variable_names,]
  })

  output$plot <- renderHighchart({
    df %>%
       hchart('line',hcaes(x = reactivedf()$date,y = reactivedf()$value))
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

我的目标只是想选择一种类型的序列

然后s 如何用折线图显示该类型,目的是学习闪亮的用法。我也不知道如何在普通ggplot中应用。
ggplot(df, aes(x = date, y = value)) + 
  geom_line(aes(color = variable), size = 1) +
  scale_color_manual(values = c("#00AFBB", "#E7B800")) +
  theme_minimal()

[如何在Shiny-折线图中继续处理数据集的反应函数,特别是不了解如何将数据集应用于react()函数以反应所选输入的#样本数据df

r ggplot2 highcharts shiny linechart
1个回答
0
投票

这应该让您接近

© www.soinside.com 2019 - 2024. All rights reserved.