iT邦幫忙

0

想用R語言建立簡單下拉式選單~~求大神指點QAQ

  • 分享至 

  • xImage

ui <- fluidPage(
titlePanel(”下拉選單範例“),
sidebarLayout(
sidebarPanel(
# 建立下拉選單
selectInput(”data_choice“, ”選擇數據集:“,
choices = c(”mtcars“, ”iris“, ”ToothGrowth“))
),
mainPanel(
tableOutput(”data_table“)
)
)
)

定義 Server 邏輯

server <- function(input, output) {
output$data_table <- renderTable({
# 根據選擇的數據集顯示對應的表格
if (input$data_choice == ”mtcars“)"" {
head(mtcars)
} else if (input$data_choice == ”iris“)"" {
head(iris)
} else if (input$data_choice == ”ToothGrowth“)"" {
head(ToothGrowth)
}
})
}

執行 Shiny App

shinyApp(ui = ui, server = server)

請問以上是否有哪錯誤 目前無法運行...

obarisk iT邦研究生 2 級 ‧ 2023-05-22 12:23:39 檢舉
reactive

不過至少給個錯誤訊息吧

什麼叫做無法運行?...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
japhenchen
iT邦超人 1 級 ‧ 2023-05-22 10:37:03

不要給我分數,如果有解決問題的話,給Bing吧!

library(shiny)

ui <- fluidPage(
  titlePanel("下拉選單範例"),
  sidebarLayout(
    sidebarPanel(
      # 建立下拉選單
      selectInput("select", "請選擇一個數字:", choices = c(1, 2, 3))
    ),
    mainPanel(
      # 顯示所選擇的數字
      textOutput("text")
    )
  )
)

server <- function(input, output) {
  output$text <- renderText({
    paste("您所選擇的數字是:", input$select)
  })
}

shinyApp(ui = ui, server = server)

我要發表回答

立即登入回答