我试图从Shiny应用程序中的checkboxGroupInput界面获取输入,然后接受该输入并在按下操作按钮时通过外部函数运行它。我不知道将输入$国家转换为该函数将接受的向量。有没有一种方法可以将该输入转换为可以使用的向量,还是必须重新设计函数以其他方式使用输入数据?谢谢!
library(shiny)
library(DT)
countries <- c("United States", "Mexico", "Canada","United Kingdom",
"Norway", "Netherlands","China", "Australia")
dataChoices <- c("Country Data", "Operator Data")
ui <- fluidPage(
titlePanel("GO-GET"),
tabsetPanel(
tabPanel(title = "Scenario",
sidebarLayout(
sidebarPanel(
actionButton(inputId = "run",
label = "Run Scenario"),
navlistPanel(
tabPanel("Country Selection",
checkboxGroupInput("countries", choices = countries,
selected = countries,
label = h3("Country Selection")
)
),
tabPanel("Country Reductions",
conditionalPanel(condition = "input.countries.includes('United
States')",
sliderInput("United States", label = "United States",
min=0, max=100, value=45)
),
conditionalPanel(condition = "input.countries.includes('Mexico')",
sliderInput("Mexico", label = "Mexico", min=0, max=100,
value=45)
),
conditionalPanel(condition = "input.countries.includes('Canada')",
sliderInput("Canada",label = "Canada", min=0, max=100,
value=45)
),
conditionalPanel(condition = "input.countries.includes('United
Kingdom')",
sliderInput("United Kingdom", label = "United Kingdom",
min=0, max=100, value=45)
),
conditionalPanel(condition = "input.countries.includes('Norway')",
sliderInput("Norway", label = "Norway", min=0, max=100,
value=45)
),
conditionalPanel(condition =
"input.countries.includes('Netherlands')",
sliderInput("Netherlandss", label = "Netherlands",
min=0, max=100, value=45)
),
conditionalPanel(condition = "input.countries.includes('China')",
sliderInput("China", label = "China", min=0, max=100,
value=45)
),
conditionalPanel(condition =
"input.countries.includes('Australia')",
sliderInput("Australia", label = "Australia", min=0,
max=100, value=45)
))),
width = 6),
mainPanel(
plotOutput("data", width = "400px"), width = 6
)
)
),
tabPanel(title = "Charts"),
tabPanel(title = "Data",
selectInput("data", label = h3("Data Selection"),
choices = dataChoices,
selected = dataChoices),
DT::dataTableOutput("table")
),
tabPanel(title = "Other")
)
)
server <- function(input, output){
output$myText <- renderText({input$countries})
cvec <- renderPrint({input$countries})
observeEvent(input$run, {
data1 <- unlist(strsplit(cvec(), split=" "))
Pathways()
output$data <- renderPlot({thermo()})
})
output$cvec <- renderPrint({input$countries})
observeEvent(input$data, {
if(input$data == "Country Data"){
output$table = DT::renderDataTable({
country_reduct
})
}
if(input$data == "Operator Data"){
output$table = DT::renderDataTable({
operator_reduct
})
}})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
我对您的帖子不太了解,但据我了解,您需要在函数中使用input$countries
。尽管不确定,但这可能会解决您的问题:
observeEvent(input$run, {
req(input$countries)
data1 <- unlist(strsplit(input$countries, split=" "))
Pathways()
output$data <- renderPlot({thermo()})
})