为(一个)闪亮的单选按钮分配多个值
assigning multiple values to (one) shiny radio button
我正在尝试使用 dashboardPage ui 开发一个闪亮的应用程序 ui 我想让我的单选按钮控制两个不同的值。
更详细一点:
考虑到我有一个这样的 df:
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959")
我的想法是 is/was 使用单选按钮 "daily" 和 "weekly" 我想 'call' 两个可能的 columns/values可以单独显示(在 valueBoxes 中)的按钮(高和低)。
有效的是这个组合:
radioButtons("radio", "Choose Period:",
c("Last 24 hours" = "dailyhigh",
"Last 7 days" = "weeklyhigh"))
还有这个:
output$high <- renderValueBox({
h = subset(mydata,select = input$radio)
valueBox(
round(h[3,1],3),"High", col='green')
})
我想要的是如下内容:
注意:这(对我)不起作用,但希望它能显示我想做的事情。
编辑: 下面的代码创建了额外的按钮。所以严格来说它确实有效,但这不是我想要的。
radioButtons("radio", "Choose Period:",
c("Last 24 hours" = c("dailyhigh","dailylow"),
"Last 7 days" = c("weeklyhigh","weeklylow")))
要使用这样的东西:
# select the daily or weekly high
#=======================================
output$high <- renderValueBox({
h = subset(mydata,select = input$radio[1])
valueBox(
round(h[3,1],3),"High", col='green')
})
# select the daily or weekly low
#=======================================
output$low <- renderValueBox({
l = subset(mydata,select = input$radio[2])
valueBox(
round(l[3,1],3), "Low", col='red')
})
谢谢
============================================= =====================
当前代码:
# =================================================== #
# ====== #
# Shiny Graph Examples #
# ===== #
# =================================================== #
# ===== #
# Packages, Libraries and Source Code
# ===== #
# === Libraries
require(shiny)
require(shinydashboard)
# === Data
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959
")
###START THE APP
# ======================
ui <- dashboardPage(
skin="yellow",
dashboardHeader(
#title="Playing with Sentiment Data",
#titleWidth = 450
),
dashboardSidebar(
radioButtons("radio", "Choose Period:",
c(
"Last 24 hours" = "dailyhigh",
"Last 7 days" = "weeklyhigh"))
),
dashboardBody(
#boxes to be put in a row (or column)
fluidRow(
valueBoxOutput("high"),
valueBoxOutput("low")
)
)
)
server <- function(input, output) {
output$high <- renderValueBox({
h = subset(mydata,select = input$radio)
valueBox(
round(h[3,1],3),"High", col='green')
})
output$low <- renderValueBox({
l = subset(mydata,select = input$radio)
valueBox(
round(l[3,1],3), "Low", col='red')
})
}
shinyApp(ui, server)
这有望为您提供所需的输出:
# =================================================== #
# ====== #
# Shiny Graph Examples #
# ===== #
# =================================================== #
# ===== #
# Packages, Libraries and Source Code
# ===== #
# === Libraries
require(shiny)
require(shinydashboard)
# === Data
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959
")
###START THE APP
# ======================
ui <- dashboardPage(
skin="yellow",
dashboardHeader(
#title="Playing with Sentiment Data",
#titleWidth = 450
),
dashboardSidebar(
radioButtons("radio", "Choose Period:",
c(
"Last 24 hours" = "daily",
"Last 7 days" = "weekly"))
),
dashboardBody(
#boxes to be put in a row (or column)
fluidRow(
valueBoxOutput("high"),
valueBoxOutput("low")
)
)
)
server <- function(input, output) {
output$high <- renderValueBox({
h = subset(mydata,select = paste(input$radio,"high",sep = ""))
valueBox(
round(h[3,1],3),"High", col='green')
})
output$low <- renderValueBox({
l = subset(mydata,select = paste(input$radio,"low",sep = ""))
valueBox(
round(l[3,1],3), "Low", col='red')
})
}
shinyApp(ui, server)
我正在尝试使用 dashboardPage ui 开发一个闪亮的应用程序 ui 我想让我的单选按钮控制两个不同的值。
更详细一点:
考虑到我有一个这样的 df:
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959")
我的想法是 is/was 使用单选按钮 "daily" 和 "weekly" 我想 'call' 两个可能的 columns/values可以单独显示(在 valueBoxes 中)的按钮(高和低)。
有效的是这个组合:
radioButtons("radio", "Choose Period:",
c("Last 24 hours" = "dailyhigh",
"Last 7 days" = "weeklyhigh"))
还有这个:
output$high <- renderValueBox({
h = subset(mydata,select = input$radio)
valueBox(
round(h[3,1],3),"High", col='green')
})
我想要的是如下内容:
注意:这(对我)不起作用,但希望它能显示我想做的事情。
编辑: 下面的代码创建了额外的按钮。所以严格来说它确实有效,但这不是我想要的。
radioButtons("radio", "Choose Period:",
c("Last 24 hours" = c("dailyhigh","dailylow"),
"Last 7 days" = c("weeklyhigh","weeklylow")))
要使用这样的东西:
# select the daily or weekly high
#=======================================
output$high <- renderValueBox({
h = subset(mydata,select = input$radio[1])
valueBox(
round(h[3,1],3),"High", col='green')
})
# select the daily or weekly low
#=======================================
output$low <- renderValueBox({
l = subset(mydata,select = input$radio[2])
valueBox(
round(l[3,1],3), "Low", col='red')
})
谢谢
============================================= =====================
当前代码:
# =================================================== #
# ====== #
# Shiny Graph Examples #
# ===== #
# =================================================== #
# ===== #
# Packages, Libraries and Source Code
# ===== #
# === Libraries
require(shiny)
require(shinydashboard)
# === Data
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959
")
###START THE APP
# ======================
ui <- dashboardPage(
skin="yellow",
dashboardHeader(
#title="Playing with Sentiment Data",
#titleWidth = 450
),
dashboardSidebar(
radioButtons("radio", "Choose Period:",
c(
"Last 24 hours" = "dailyhigh",
"Last 7 days" = "weeklyhigh"))
),
dashboardBody(
#boxes to be put in a row (or column)
fluidRow(
valueBoxOutput("high"),
valueBoxOutput("low")
)
)
)
server <- function(input, output) {
output$high <- renderValueBox({
h = subset(mydata,select = input$radio)
valueBox(
round(h[3,1],3),"High", col='green')
})
output$low <- renderValueBox({
l = subset(mydata,select = input$radio)
valueBox(
round(l[3,1],3), "Low", col='red')
})
}
shinyApp(ui, server)
这有望为您提供所需的输出:
# =================================================== #
# ====== #
# Shiny Graph Examples #
# ===== #
# =================================================== #
# ===== #
# Packages, Libraries and Source Code
# ===== #
# === Libraries
require(shiny)
require(shinydashboard)
# === Data
mydata <- read.table(header=TRUE, text="
dailyhigh dailylow weeklyhigh weeklylow
3.173455 0.44696251 2.520812 0.9406211
2.923370 1.60416341 3.481743 0.9520305
2.584739 0.05719436 4.534701 0.6622959
")
###START THE APP
# ======================
ui <- dashboardPage(
skin="yellow",
dashboardHeader(
#title="Playing with Sentiment Data",
#titleWidth = 450
),
dashboardSidebar(
radioButtons("radio", "Choose Period:",
c(
"Last 24 hours" = "daily",
"Last 7 days" = "weekly"))
),
dashboardBody(
#boxes to be put in a row (or column)
fluidRow(
valueBoxOutput("high"),
valueBoxOutput("low")
)
)
)
server <- function(input, output) {
output$high <- renderValueBox({
h = subset(mydata,select = paste(input$radio,"high",sep = ""))
valueBox(
round(h[3,1],3),"High", col='green')
})
output$low <- renderValueBox({
l = subset(mydata,select = paste(input$radio,"low",sep = ""))
valueBox(
round(l[3,1],3), "Low", col='red')
})
}
shinyApp(ui, server)