我想创建一个可点击的直方图,shiny但我不知道是否可行。
几个月前,我看到了一个可点击的火山图,它为您提供了您点击的内容的表格。
来源:https ://2-bitbio.com/2017/12/clickable-volcano-plots-in-shiny.html
我发现的关于创建可点击直方图的最接近的帖子是这个Click to get Cocoes from multiple histogram in sunny
但是,我不想获得坐标。我想要数据框的行名。
有了这个数据框,每次单击直方图中的条形时我可以获取行名吗?
mtcars <- mtcars %>%
select("hp")
mtcars <- as.matrix(mtcars)
Run Code Online (Sandbox Code Playgroud)
一个闪亮的例子(但不可点击):
library(shiny)
library(ggplot2)
library(scales)
library(dplyr)
ui <- fluidPage(
titlePanel("Histogram"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
plotOutput("hist"),
)
)
)
mtcars <- mtcars %>%
select("hp")
mtcars <- as.matrix(mtcars)
server <- function(input, output) {
output$hist <- renderPlot({
pp <- qplot(mtcars, geom = "histogram", bins = 10, xlab="values",
ylab="Frequency", main="Histogram",
fill=I("red"), col=I("black"), alpha=I(0.4))
pp + scale_x_continuous(breaks=pretty(mtcars, n=10))
}) …Run Code Online (Sandbox Code Playgroud) 这是一个例子。我想要的是用户可以通过按钮多次运行演示DEMO。但是,当他们单击Browse上传本地数据(不是reset我在示例中演示的按钮)时,我会弹出一个窗口,让用户在两个输入框中输入他们的姓名和状态。在下面的示例中,通过单击RESET,将启动一个弹出框(可能不是正确的方式)。
library(shiny)
library(shinyWidgets)
if (interactive()) {
# Display an important message that can be dismissed only by clicking the
# dismiss button.
shinyApp(
ui <- fluidPage(
tabsetPanel(
##tabPanel-Input
tabPanel("Input", fluid = TRUE,
# tab title ----
titlePanel("Upload data"),
# sidebar layout with input and output tables ----
sidebarLayout(
# sidebar panel for inputs ----
sidebarPanel(
#show ct demo
actionBttn("runexample", "DEMO", style="simple", size="sm", color = "primary"),
# input1: Select a file ----
fileInput("file1", …Run Code Online (Sandbox Code Playgroud) 我刚刚发现 DT 包有一个扩展,使您有机会获取 CSV、PDF 等形式的表格。第一次,条目没有出现,但我看到如果我写dom = 'Blfrtip'它们就会出现。
但是,有没有办法可以选择“显示表的所有条目”?
现在,最大条目数为 100。
代码:
datatable(
iris, extensions = 'Buttons', options = list(
dom = 'Blfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
)
Run Code Online (Sandbox Code Playgroud)
提前致谢,
问候
我正在尝试使用 heatmaply 包来绘制热图,并且效果很好。
另一方面,当我尝试在 Shiny 中执行相同的绘图时,它不会出现在界面中(当我单击“运行应用程序”时)。但是,当我突然关闭窗口时,绘图会出现在 R 查看器中。heatmaply 包是否可能无法与 Shiny 一起使用?
这是我在 R 中绘制的代码。
library(heatmaply)
x <- as.matrix(datasets::mtcars)
rc <- colorspace::rainbow_hcl(nrow(x))
heatmaply(
x[, -c(8, 9)],
col_side_colors = rc[1:9],
showticklabels=FALSE,
Rowv = TRUE,
Colv = FALSE
)
Run Code Online (Sandbox Code Playgroud)
这是我在 Shiny 中的代码。
library(shiny)
library(heatmaply)
ui <- fluidPage(
# Application title
titlePanel("Heatmap"),
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
x <- as.matrix(datasets::mtcars)
rc <- colorspace::rainbow_hcl(nrow(x))
server <- function(input, output) {
output$distPlot <- renderPlot({
heatmaply(
x[, …Run Code Online (Sandbox Code Playgroud) 这是我的数据:
\ndat <- mtcars\ndat$Brands <- rownames(dat)\ndat$Info <- rep("Info", length(rownames(mtcars)))\nRun Code Online (Sandbox Code Playgroud)\n我已经看到有很多方法可以对整个数据框架执行某些操作。mutate,sapply等等。但是,对于某些特定功能它不起作用。
最接近的例子是如果你想做的话log2+1。
我已经尝试过这个...
\ndata_log <- dat %>% mutate(across(where(is.numeric), log2+1))\nRun Code Online (Sandbox Code Playgroud)\n但这给了我这个错误......
\n\n\n错误:
\nmutate()输入有问题..1。\n\xe2\x84\xb9..1 = across(where(is.numeric), log2 + 1)。\nx 二元运算符的非数字参数\n运行rlang::last_error()以查看发生错误的位置。
您知道是否有办法运行此类功能?
\n