如何从选择性输入中选择反应性参数?
How to Choose Reactive Argument from a Selective Input?
我有一个 Select 框输入,它根据加载的 .csv
文件的列名而变化。这就是我的 observeEvent
函数的作用。
我在绘制 server.R
中的输出时遇到了问题,因为我不确定如何制作反应参数以将 SelectizeInput
的输出转换为所选列来自 Select 框。有谁知道我应该在 renderDygraph
输出中放入什么来绘制我从 SelectizeInput
中选择的频道?
这是我的代码:
ui.R
shinyUI(fluidPage(
# Application title
titlePanel("Graph"),
fluidRow(
column(6,
wellPanel(`
selectInput("dataSelection1", label = "Choose a File",
choices = c("File1")),
selectizeInput("channel1", label = "Choose a Channel",
choices = NULL))),
column(12, dygraphOutput("Graph")
)
)
)
)
server.R
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
component <- switch(input$channel1,
**'WHAT TO PUT IN HERE?'**)
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})
我认为您不能使用 switch 语句,因为您事先不知道将其等同于什么,但我会这样做:
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
data <- dataSource1()
selected_input <- input$channel1
component <- data[, selected_input]
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})
我有一个 Select 框输入,它根据加载的 .csv
文件的列名而变化。这就是我的 observeEvent
函数的作用。
我在绘制 server.R
中的输出时遇到了问题,因为我不确定如何制作反应参数以将 SelectizeInput
的输出转换为所选列来自 Select 框。有谁知道我应该在 renderDygraph
输出中放入什么来绘制我从 SelectizeInput
中选择的频道?
这是我的代码:
ui.R
shinyUI(fluidPage(
# Application title
titlePanel("Graph"),
fluidRow(
column(6,
wellPanel(`
selectInput("dataSelection1", label = "Choose a File",
choices = c("File1")),
selectizeInput("channel1", label = "Choose a Channel",
choices = NULL))),
column(12, dygraphOutput("Graph")
)
)
)
)
server.R
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
component <- switch(input$channel1,
**'WHAT TO PUT IN HERE?'**)
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})
我认为您不能使用 switch 语句,因为您事先不知道将其等同于什么,但我会这样做:
shinyServer(function(input, output, session) {
dataSource1 <- reactive({
switch(input$dataSelection1,
"File1" = File1)
})
observeEvent(input$dataSelection1, {
updateSelectizeInput(session, 'channel1', choices = names(dataSource1()))
})
output$TempRise <- renderDygraph({
data <- dataSource1()
selected_input <- input$channel1
component <- data[, selected_input]
dygraph(component, main = "Data Graph") %>%
dyRangeSelector() %>%
dyOptions(colors = RColorBrewer::brewer.pal(8, "Dark2"))
})
})